如何在命令行上没有Gradle的情况下构建Android APK? [英] How can I build an Android apk without Gradle on the command line?

查看:227
本文介绍了如何在命令行上没有Gradle的情况下构建Android APK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个不使用依赖项或模块的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.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-命令行

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

这篇关于如何在命令行上没有Gradle的情况下构建Android APK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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