如何在命令行上没有Gradle的情况下构建Android APK? [英] How can I build an Android apk without Gradle on the command line?
问题描述
我编写了一个不使用依赖项或模块的Android应用程序,该应用程序只有一个活动,并且只有一个布局文件.
I wrote an Android app that uses no dependencies or modules, has a single activity, and has a single layout file.
如何在不使用Gradle(或其他构建系统"或依赖关系管理"软件)的情况下在命令行上构建应用程序的apk文件?
How can I build an apk file of my app on the command line without using Gradle (or other "build systems" or "dependency management" software)?
推荐答案
如果不想使用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://spin .atomicobject.com/2011/08/22/building-android-application-bundles-apks-by-hand/
这篇关于如何在命令行上没有Gradle的情况下构建Android APK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!