johndodo
johndodo

Reputation: 18291

how do I replace XML file in APK?

I would like to include additional (per-user) data in each downloaded APK file. In other words, I have an existing APK file on server and would like to:

More info: I know it can be done using aapt, apktool, jarsigner,... The problem is that the documentation is quite poor and I was unable to find (or develop) a working technique to re-pack the APK file. For instance aapt always puts the XML file in root path (/) no matter what I do. I am also unsure which resources need to be updated so that the APK file is valid again. Also, the existing XML files in /res/ are compiled - do I need to do that with my XML file too? If yes, how do I do that? If no, should I put my XML file in /res/raw/?

Question: how do I replace an XML file in APK and repackage it? What steps are needed and which tools do I use?

Upvotes: 6

Views: 7402

Answers (1)

Akdeniz
Akdeniz

Reputation: 1270

In this writing you can find the basic steps of unpacking and packing an apk file.

Basicly;

= Use apktool.bat d -s sample.apk .\sample\ to decode only resources of the apk.(In your situation there is no need to decode source part)

= Add/edit/replace your required resources.

= Use apktool.bat b .\sample\ .\sample_edited.apk to build changed apk.

= Generate a RSA 2048 key to sign apk if you dont already have one : keytool -genkey -v -keystore my.keystore -alias myandroidalias -keyalg RSA -keysize 2048 -validity 20000

= Sign apk with generated key jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore my.keystore .\sample_edited.apk -signedjar .\sample_signed.apk myandroidalias

= And align signed apk with 4-byte boundary zipalign.exe -v 4 .\sample_signed.apk .\sample_aligned.apk (zipalign comes with the android-sdk)

Upvotes: 5

Related Questions