更新时间: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.apk
或 MyApplication-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/