使用我的桌面应用程序的用户如何在客户端修改预打包的 apk 文件?
好吧,我知道标题写得不好,但我的情况就是这么复杂!我在这里搜索了这个案例,但其他类似的问题确实与我的不同。
这是我的问题:
- 我编写了一个Android程序,它显示存储在“assets”文件夹中的内容(原始格式的文本、图像等)。现在我想将此应用程序与 Windows 应用程序(也是由我编写)一起交付给最终用户,这使他们可以将内容添加到 apk 文件的“assets”文件夹中,并使用他们想要的名称输出修改后的 apk(以显示在他们的电话)。
现在执行此操作的最佳解决方案是什么以及我应该使用哪些工具和命令?我的意思是我应该在我的软件中包含哪些工具(aapt、jarsigner...)以及必须启动哪些命令我的软件可以做到这一点吗?
有关我的案例的更多信息:
- 我的用户不高级,对 Android 编程和修改 apk 一无所知,我希望他们只使用我的客户端 Windows 应用程序。
- 我不想在客户端计算机上使用 JDK、JRE...。
- 修改过程包括:替换AndroidManifest.xml和drawable\icon.png,并在assets文件夹中添加一些文件。
- 我将分发我的密钥库文件和未签名的原始 apk 文件以及要在流程结束时签名的软件。
PS: 好的,几个小时后,我几乎通过 9 个步骤找到了解决方案,并获得了最终的自定义签名 zip 对齐 apk 文件并安装在设备上,没有错误!但现在的问题是:我的用户生成的所有 apk 文件都具有相同的包名称 (com.MyName.MyApp),如果有人在手机上安装 2 个或更多这些文件,就会出现问题。我应该尝试“aapt --rename-manifest-package”来解决这个问题吗?以及如何使用它?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于得到了这个可行的解决方案,我将其放在这里供任何感兴趣的人使用。
1- 将“original.apk”(source.apk)提取到临时文件夹(即 TempFolder)
2- 将用户生成的文件放入 TempFolder 下的“assets”和“res\drawable”文件夹中
3- 生成 AndroidManifest.xml 并放入在 TempFolder
4 中 - 运行以下命令:
aapt package -f -M "PathToManifest" -S "PathToResFolder" -I android.jar -F "NearlyFinal.apk" -A "PathToAssetsFolder"
5- 将“classes.dex”复制到 NearlyFinal.apk 所在的文件夹。
6-运行此命令:
aapt add -f NearlyFinal.apk classes.dex jad.properties
7- 签名 apk 文件:
jarsigner -storepass [keystorePass] -keystore KeyStoreFile.key NearlyFinal.apk [KeyStoreName]
8- zipalign apk 文件:
zipalign 4 NearlyFinal.apk "Final.apk"
9- 根据用户的偏好重命名并移动 Final.apk。
结束
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