How to modify the data in the assets folder in existing apk programmatically?

KomalG picture KomalG · Jun 8, 2015 · Viewed 7.2k times · Source

I want to replace one file in the assets folder with generated apk(in the assets folder there is sample.txt file after generating the apk i want to change the data in that file and regenerate the new apk ).

===> old APK+modified(sample.txt)=newApk

How to do this?

Answer

CommonsWare picture CommonsWare · Jun 8, 2015

An APK file is a ZIP archive, and assets are not modified as part of the build process. So, on your development machine, you can:

  • unZIP the APK file
  • replace your assets
  • ZIP the result back into an APK file
  • use jarsigner to sign the APK with your production keystore
  • use zipalign to align the results on four-byte boundaries for faster loading at runtime