且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在命令行上构建没有 Gradle 的 Android apk?

更新时间:2023-01-05 22:57:08

如果您不想使用 ant/gralde 构建,请使用以下步骤手动构建您的 apk.但你必须至少安装 Android SDK.

Use the following steps to build your apk manually, if you don't want use ant/gralde to build. But you must have Android SDK installed at least.

  • aapt

使用javac将所有java源码编译为*.class

use javac to compile all java source to *.class

使用dx将所有*.class转换为dex文件,例如输出为classes.dex代码>

use dx to convert all *.class to dex file, e.g output is classes.dex

从资产、资源和 AndroidManfiest.mk 创建初始版本的 APK,例如输出是 MyApplication.apk.unaligned

create initial version of APK from assets, resources and AndroidManfiest.mk, e.g output is MyApplication.apk.unaligned

使用aapt将步骤3中生成的classes.dex添加到MyApplication.apk.unaligned

use aapt to add classes.dex generated in step 3 to MyApplication.apk.unaligned

使用 jarsigner 对 MyApplication.apk.unaligned 和调试或发布密钥进行签名

use jarsigner to sign MyApplication.apk.unaligned with debug or release key

使用 zipalign 对齐最终的 APK,例如输出是 MyApplication-debug.apkMyApplication-release.apk 如果使用发布密钥签名

use zipalign to align the final APK, e.g output is MyApplication-debug.apk or MyApplication-release.apk if signing with release key

完成

我已经创建了一个示例脚本来完成上述所有操作,请参阅 这里

I have created a sample script to do all the stuffs above, see here

其实有些文章已经讨论过这个话题,请看下面的链接.

Actually, Some articles have discussed this topic, see the following links.

https://www.apriorit.com/dev-blog/233-how-to-build-apk-file-from-command-line

https://spin.atomicobject.com/2011/08/22/building-android-application-bundles-apks-by-hand/