I have a .apk file in assets folder.I want to unzip that .apk file and insert a file in it and generate a .apk from mobile. How can i achieve it? give any suggestions.
-
You cannot unzip a apk file. You have to decompile it if possible.. – Oli May 16 '13 at 13:09
-
what do you want to do exactly? do you want to install a apk from assets folder? – Qadir Hussain May 16 '13 at 13:10
-
@Oli: You can! unzip an apk file because the compress algorythm is zip based. – Reporter May 16 '13 at 13:16
-
@Reporter Oh ok, thanks ;) - to get the assets db its usefull – Oli May 16 '13 at 13:19
-
@user2380107 can you give us some background informations? – Oli May 16 '13 at 13:20
-
Maybe http://stackoverflow.com/questions/3048669/how-can-i-add-entries-to-an-existing-zip-file-in-java and the menthonied related links can help for your task. – Reporter May 16 '13 at 13:25
-
@Hussain: I want to install that .apk from assets folder before that i want to insert a .sql file into it. (is this process is possible under mobile?) – Shylendra May 20 '13 at 04:44
2 Answers
APK files are ZIP files, therefore the classes below java.util.zip should serve you well. Note that deleting a file from a ZIP file is not that simple - therefore it would be easier to have an APK file without the file to be modified and the file separately. Adding the modified file to the APK is much simpler.
Furthermore you have to consider that a modified APK file can not be installed on Android as it's signature is invalid. Hence you have to re-sign.
Unfortunately the tool for signing an JAR/APK file is only included in the Java SDK and it is a native program for x86 which can't be executed on Android/ARM.
Edit 2023-06: Google provides the apksig library (pure Java) which can sign (or verify) an APK file. The only part that is left is the aligning before signing. There is the zipalign-java project which seem to be able to handle most alignment cases.

- 39,162
- 17
- 99
- 152
-
I haven't tested this, but you may need to rename the extension to .zip. ZipFile will work, though. – Snailer May 16 '13 at 14:45
-
1No, The programs and your code don't care about extensions. Only on Windows if you double click the file the extension matters. – Robert May 16 '13 at 14:52
-
Ah, ok. I know code doesn't care, but I wasn't sure if any of the zip API threw something if the file wasn't a recognized extension (zip,tar,etc) – Snailer May 16 '13 at 16:10
-
@Robert: So is it possible to create a modified .apk (which can be installable on mpbile) from mobile and store it in external sd_card? – Shylendra May 20 '13 at 04:55
-
-
You have to add the MD5 hash of each file in the APK file into the MANIFEST.MF and the sign the MANIFEST.MF with an self-signed certificate. See http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#Signature_File – Robert May 22 '13 at 07:34
You CAN do this. First, you have to:
- Change the file extension from .apk to .zip.
- Unzip it and now it became a folder.
- Change, delete what you want.
- Zip the folder.
- Change the extension to from .zip to .apk
- Sign the APK using apksigner.
- Install it.

- 25
- 3
- 13