25

I'm using ApkTool to decode AndroidManifest.xml inside an APK file and it works perfectly but how can I encode it again ,the same way it was encoded before, after applying some changes? For example (in my case) changing the app label.

copolii
  • 14,208
  • 10
  • 51
  • 80
Soheil Setayeshi
  • 2,343
  • 2
  • 31
  • 43
  • 1
    Ask the developer for the original code or download the source. If you are reverse engineering someone else's code, then no help here. – Simon May 27 '13 at 16:48
  • 1
    @Simon dude I was that someone else in this case cause I was just trying create an app-generator from a template "apk" file that I wrote before and trying change its data from outside and sign it again ;) – Soheil Setayeshi Jul 13 '15 at 08:38

2 Answers2

36

You may use apktool again to create a new APK file including your changed AndroidManifest.xml.

First, decompile the APK file:

java -jar apktool.jar decode app.apk app

Then modify the files you want in the app directory and recompile it back into a new APK:

java -jar apktool.jar build app app_new.apk

aapt must be on our PATH or use the --aapt option to specify the location of the executable. Otherwise apktool will fail when rebuilding the APK.

Note: The rebuilt APK is neither signed nor zipaligned, just repackaged. Take a look at this website for details about signing and aligning your new APK.

nif
  • 3,342
  • 20
  • 18
  • 4
    Note that in version 2.0.0 of ApkTool, either you do not specify the "app" directory or you introduce it using the option -o – Mikaël Mayer Apr 21 '15 at 15:41
  • 1
    Is there a way to do this without repackaging the entire APK? Because `apktool` often fails to decompile then recompile with no modifications. – 0xcaff Jul 15 '15 at 16:35
  • I get `Input file (app) was not found or was not readable.` error. What does it mean ? If I omit last parameter I cannot build apk again. – expert Jan 06 '18 at 12:55
  • @expert it's because you're specifying a directory app, ommit "app" from the command. Apktool will automatically create a folder named base if the apk name was base.apk. on newer versions of apktool there's an option -o for output directory. enjoy =) – Viktova Aug 23 '18 at 08:38
4
Use appt for android-sdk (ex:- /build-tools/27.0.3/aapt )

./aapt d xmltree ./debug.apk  AndroidManifest.xml

N: android=http://schemas.android.com/apk/res/android
  E: manifest (line=1)
    A: android:versionCode(0x0101021b)=(type 0x10)0x1
    A: android:versionName(0x0101021c)="1.0" (Raw: "1.0")
    A: package="com.example.activity" (Raw: "com.example.activity")
    E: uses-sdk (line=6)
      A: android:minSdkVersion(0x0101020c)=(type 0x10)0x8
      A: android:targetSdkVersion(0x01010270)=(type 0x10)0xf
    E: application (line=8)
      A: android:label(0x01010001)=@0x7f030000
      A: android:icon(0x01010002)=@0x7f020000
      E: activity (line=10)
        A: android:label(0x01010001)=@0x7f030000
        A: android:name(0x01010003)=".SampleActivity" (Raw: ".SampleActivity")
        E: intent-filter (line=12)
          E: action (line=13)
            A: android:name(0x01010003)="android.intent.action.MAIN" (Raw: "android.intent.action.MAIN")
          E: category (line=14)
            A: android:name(0x01010003)="android.intent.category.LAUNCHER" (Raw: "android.intent.category.LAUNCHER")

This link might help http://elinux.org/Android_aapt

Another one tool for "AXMLPrinter" google source link https://code.google.com/archive/p/android4me/downloads

java -jar ./AXMLPrinter2.jar ./debug.apk_FILES/AndroidManifest.xml

  • Another one tool for AXMLPrinter. note this link google source (https://code.google.com/archive/p/android4me/downloads) java -jar ./AXMLPrinter2.jar ./debug.apk_FILES/AndroidManifest.xml – Tamilan C.Periyasamy Sep 09 '18 at 09:14