How to modify a pre-packaged apk file on client-side by user who is using my desktop application?

本秂侑毒 提交于 2019-11-29 16:32:35

问题


Well, I know the title is not well-written, but my case is as complicated as that! I searched for this case here but other similar questions really differ from mine.

Here is my problem:

  • I have written an Android program which displays contents (text, images, etc. in raw format) that is stored in "assets" folder. Now I want to deliver this app along with a windows application (also written by me) to end users, which lets them add contents to "assets" folder of the apk file and output the modified apk with their desired name (to appear on their phone).

Now what is best solution to do this and which tools and commands I should use? I mean which tools (aapt, jarsigner, ...) I should include in my software and which commands must be launched by my software to do this?

More info about my case:

  • My users aren't advanced and don't know anything about Android programming and modifying apk, and I want them to only use my client windows application.
  • I want not to use JDK, JRE, ... on client's machine.
  • Modification process includes: replacing AndroidManifest.xml and drawable\icon.png and adding some files to assets folder.
  • I would distribute my keystore file and unsigned original apk file along with my software to be signed at the end of process.

P.S: OK, after some hours I nearly found solution in 9 steps and got final custom-signed-zip-aligned apk file and installed on device without errors! But now the problem is: all of apk files that would be produced by my users would have same package name (com.MyName.MyApp) and would cause problem if someone installs 2 or more of them on their phones. Should I try "aapt --rename-manifest-package" for this problem? and how to use it?


回答1:


I finally have ended up with this working solution, I put it here for anyone interested.

1- Extract "original.apk" (source.apk) to a temp folder (ie. TempFolder)

2- Put user-generated files in "assets" and "res\drawable" folders under TempFolder

3- generate AndroidManifest.xml and put in TempFolder

4- Run this command: aapt package -f -M "PathToManifest" -S "PathToResFolder" -I android.jar -F "NearlyFinal.apk" -A "PathToAssetsFolder"

5- copy "classes.dex" to folder where NearlyFinal.apk exists.

6- run this command: aapt add -f NearlyFinal.apk classes.dex jad.properties

7- sign apk file: jarsigner -storepass [keystorePass] -keystore KeyStoreFile.key NearlyFinal.apk [KeyStoreName]

8- zipalign apk file: zipalign 4 NearlyFinal.apk "Final.apk"

9- rename and move Final.apk according to user's pref's.

FINISH



来源:https://stackoverflow.com/questions/7360149/how-to-modify-a-pre-packaged-apk-file-on-client-side-by-user-who-is-using-my-des

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!