8

How do I manually add a file to an Android APK package?

zer0stimulus
  • 22,306
  • 30
  • 110
  • 141
  • I don't think it's possible since you'd need to re-sign the apk again. as well. You mean from within your app programmatically, right - or into the already packages apk without having to rebuild everything? – Mathias Conradt Aug 21 '10 at 01:52
  • I mean the latter- manually insert a file into a built APK – zer0stimulus Aug 23 '10 at 13:49

3 Answers3

10

There's a tool called aapt that is bundled with the Android SDK. You can use it to add/remove/list files in an existing apk. Run aapt without any params and it will print usage instructions. To add a file use:

aapt add MyApp.apk file1 file2 ...
enrico.bacis
  • 30,497
  • 10
  • 86
  • 115
svoisen
  • 3,292
  • 1
  • 18
  • 8
8

An apk is a jar which is a zip. So you can use any tool that manipulates zips.

There is an added complication however: the Android platform requires all files in the apk (except for the files in the META-INF directory) to be signed. So you need to call jarsigner again to sign all packages. You should then also call zipalign again.

You must sign the modified apk with the same key that was used to sign the original apk. This is the whole point of the signature: it indicates that the package has not been tampered with without the approval of the signer. (Actually, you can sign with a different key, but then you won't be able to access any data that was produced by the original application or vice versa.)

The ant scripts provided with the Android development kit contain automation to run jarsigner and zipalign.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
  • It should be `META-INF` directory been ignored, not MANIFEST. The verification is implemented in PackageParser.collectCertificates() – Wu Yongzheng Apr 09 '15 at 06:59
0

or you could just open it,insert the file, goto

META-INF>MANIFEST.MF

Get the file you want to inserts

SHA1 - Checksum

Add it to the Manifest.

user3343456
  • 103
  • 2
  • 9