[英]How can I build an Android apk without Gradle on the command line?
I wrote an Android app that uses no dependencies or modules, has a single activity, and has a single layout file.我编写了一个 Android 应用程序,它不使用任何依赖项或模块,只有一个活动,并且只有一个布局文件。
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)?如何在不使用 Gradle(或其他“构建系统”或“依赖管理”软件)的情况下在命令行上构建我的应用程序的 apk 文件?
Use the following steps to build your apk manually, if you don't want use ant/gralde to build.如果您不想使用 ant/gralde 构建,请使用以下步骤手动构建您的 apk。 But you must have Android SDK installed at least.但你必须至少安装 Android SDK。
create R.java
from aapt
从aapt
创建R.java
use javac
to compile all java source to *.class
使用javac
将所有 java 源码编译为*.class
use dx
to convert all *.class
to dex
file, eg output is classes.dex
使用dx
将所有*.class
转换为dex
文件,例如输出为classes.dex
create initial version of APK from assets, resources and AndroidManfiest.mk
, eg output is MyApplication.apk.unaligned
从资产、资源和AndroidManfiest.mk
创建初始版本的 APK,例如输出是MyApplication.apk.unaligned
use aapt
to add classes.dex
generated in step 3 to MyApplication.apk.unaligned
使用aapt
将步骤 3 中生成的classes.dex
添加到MyApplication.apk.unaligned
use jarsigner to sign MyApplication.apk.unaligned
with debug or release key使用 jarsigner 签署MyApplication.apk.unaligned
与调试或发布密钥
use zipalign
to align the final APK, eg output is MyApplication-debug.apk
or MyApplication-release.apk
if signing with release key使用zipalign
对齐最终的 APK,例如,如果使用发布密钥签名,则输出为MyApplication-debug.apk
或MyApplication-release.apk
Done完毕
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://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/ https://spin.atomicobject.com/2011/08/22/building-android-application-bundles-apks-by-hand/
alijandro gave a perfect answer. alijandro给出了完美的答案。 I managed to write simple ANT script that builds production APK with AdMob and without gradle usage.我设法编写了简单的 ANT 脚本,该脚本使用 AdMob 构建生产 APK,无需使用 gradle。 A couple useful comments:一些有用的评论:
If you want to obfuscate classes you have to jar the compiled classes (between javac
and dx
steps) and run proguard
on it如果你想混淆类,你必须 jar 编译的类(在javac
和dx
步骤之间)并在它上面运行proguard
For AdMob
you have to extract the following jars from zip archives (like C:\\Users\\<User>\\AppData\\Local\\Android\\sdk\\extras\\google\\m2repository\\com\\google\\android\\gms\\play-services-ads\\10.2.6\\play-services-ads-10.2.6.aar
):对于AdMob
您必须从 zip 存档中提取以下 jar(例如C:\\Users\\<User>\\AppData\\Local\\Android\\sdk\\extras\\google\\m2repository\\com\\google\\android\\gms\\play-services-ads\\10.2.6\\play-services-ads-10.2.6.aar
):
These archives should be passed in javac
and dx
这些档案应该在javac
和dx
传递
AdMob
there are several additional simple config steps as well对于AdMob
还有几个额外的简单配置步骤Gradle
does a lot of mess with android projects, so own script looks like a singular solution for projects that are going to go into production Gradle
对 android 项目做了很多处理,所以自己的脚本看起来像是将要投入生产的项目的单一解决方案
Try this for building apps with support libraries from command line.尝试使用此方法从命令行构建具有支持库的应用程序。 https://github.com/HemanthJabalpuri/AndroidExplorer https://github.com/HemanthJabalpuri/AndroidExplorer
The short answer is: U can't 简短的答案是:你不能
And the long is: 长是:
The process of creating apk is not as easy as it seams. 创建apk的过程并不容易。 https://developer.android.com/studio/build/index.html https://developer.android.com/studio/build/index.html
So not only you would need to: 因此,不仅您需要:
But well do a lot, a and i really mean it 但是很好,很多,我真的是说真的
There is a bit. 有一点。
Where if u use Android studio 如果您使用Android Studio
Even better you can use simple commands to run those task 更好的是,您可以使用简单的命令来运行这些任务
./gradlew assembleRelease
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.