开发者

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

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开发者_如何学Python, ...) 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜