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

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

问题描述

我编写了一个 Android 应用,它不使用任何依赖项或模块,只有一个 Activity 和一个布局文件.

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-command-line

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

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

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