使用我的桌面应用程序的用户如何在客户端修改预先打包的 apk 文件? [英] How to modify a pre-packaged apk file on client-side by user who is using my desktop application?

查看:17
本文介绍了使用我的桌面应用程序的用户如何在客户端修改预先打包的 apk 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我知道标题写得不好,但我的情况就是这么复杂!我在这里搜索了这个案例,但其他类似的问题与我的完全不同.

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.

这是我的问题:

  • 我编写了一个 Android 程序,用于显示存储在assets"文件夹中的内容(原始格式的文本、图像等).现在我想将这个应用程序和一个 Windows 应用程序(也是我写的)一起交付给最终用户,这让他们可以将内容添加到 apk 文件的assets"文件夹中,并使用他们想要的名称输出修改后的 apk(出现在他们的电话).

现在什么是最好的解决方案,我应该使用哪些工具和命令?我的意思是我应该在我的软件中包含哪些工具(aapt,jarsigner,...)以及哪些命令必须由我的软件启动以执行此操作?

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:

  • 我的用户并不高级,对 Android 编程和修改 apk 一无所知,我希望他们只使用我的客户端 Windows 应用程序.
  • 我不想在客户端的机器上使用 JDK、JRE 等.
  • 修改过程包括:替换AndroidManifest.xmldrawable\icon.png,添加一些文件到assets文件夹.
  • 我会分发我的密钥库文件和未签名的原始 apk 文件以及我要在流程结束时签名的软件.
  • 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.

附注:好的,几个小时后,我几乎在 9 个步骤中找到了解决方案,并获得了最终自定义签名的 zip 对齐的 apk 文件,并没有错误地安装在设备上!但现在的问题是:我的用户生成的所有 apk 文件都具有相同的包名称 (com.MyName.MyApp),如果有人在他们的手机上安装了 2 个或更多的包,则会导致问题.我应该针对这个问题尝试aapt --rename-manifest-package"吗?以及如何使用它?

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- 将original.apk"(source.apk)提取到临时文件夹(即TempFolder)

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

2- 将用户生成的文件放在 TempFolder 下的assets"和res\drawable"文件夹中

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

3- 生成 AndroidManifest.xml 并放入 TempFolder

3- generate AndroidManifest.xml and put in TempFolder

4- 运行此命令:aapt 包 -f -M "PathToManifest" -S "PathToResFolder" -I android.jar -F "NearlyFinal.apk" -A "PathToAssetsFolder"

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

5- 将classes.dex"复制到 NearlyFinal.apk 所在的文件夹.

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

6- 运行此命令:aapt add -f NearlyFinal.apk classes.dex jad.properties

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

7- 签署 apk 文件:jarsigner -storepass [keystorePass] -keystore KeyStoreFile.key NearlyFinal.apk [KeyStoreName]

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

8- zipalign apk 文件:zipalign 4 NearlyFinal.apk "Final.apk"

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

9- 根据用户的偏好重命名和移动 Final.apk.

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

完成

这篇关于使用我的桌面应用程序的用户如何在客户端修改预先打包的 apk 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆