6

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?

KomalG
  • 808
  • 9
  • 18
  • Are you referring to doing this at build time (on your development machine) or at runtime (your app updating its own assets)? The latter is not possible. – CommonsWare Jun 08 '15 at 12:05
  • I will ask again: *where* are you looking to modify the assets? Are you looking to do this work on your development machine, or are you looking to do this at runtime on the Android device? – CommonsWare Jun 08 '15 at 12:15
  • in development machine – KomalG Jun 08 '15 at 12:18
  • The question is not a duplicate of the linked question, as it is not talking about runtime. – etarion Nov 03 '17 at 15:41

2 Answers2

14

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
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

It is not possible, except by deploying an updated APK. APKs are digitally signed and cannot be modified at runtime

Kanaiya Katarmal
  • 5,974
  • 4
  • 30
  • 56