How can I build an Android apk without Gradle on the command line?
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.
create
R.java
fromaapt
use
javac
to compile all java source to*.class
use
dx
to convert all*.class
todex
file, e.g output isclasses.dex
create initial version of APK from assets, resources and
AndroidManfiest.mk
, e.g output isMyApplication.apk.unaligned
use
aapt
to addclasses.dex
generated in step 3 toMyApplication.apk.unaligned
use jarsigner to sign
MyApplication.apk.unaligned
with debug or release keyuse
zipalign
to align the final APK, e.g output isMyApplication-debug.apk
orMyApplication-release.apk
if signing with release keyDone
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/
Try this for building apps with support libraries from command line. https://github.com/HemanthJabalpuri/AndroidExplorer
alijandro gave a perfect answer. I managed to write simple ANT script that builds production APK with AdMob and without gradle usage. A couple useful comments:
If you want to obfuscate classes you have to jar the compiled classes (between
javac
anddx
steps) and runproguard
on itFor
AdMob
you have to extract the following jars from zip archives (likeC:\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
):- play-services-ads-10.2.6.jar
- play-services-ads-lite-10.2.6.jar
- play-services-base-10.2.6.jar
- play-services-basement-10.2.6.jar
- play-services-clearcut-10.2.6.jar
- play-services-gass-10.2.6.jar
- play-services-tasks-10.2.6.jar
These archives should be passed in javac
and dx
- For
AdMob
there are several additional simple config steps as well
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