As a person who are using a very minimal development environment, using build system such as Gradle, Cmake and such adds another layer of complexity, eating your precious RAM, and generally made me overwhelmed because of how many files it generates, so that's why I am doing this.
- OpenJDK (preferably OpenJDK 21, it can be higher)
- AAPT2 (from Termux Packages repository)
- D8 (from cmdline-tools)
- Zipalign
- Keytool
- Apksigner
$JAVA_HOMEset to$PREFIX/lib/jvm/java-YY-openjdk$ANDROID_HOMEpreferably set to$HOME/.local/share/android$PATHset to$PATH:$ANDROID_HOME/cmdline-tools/latest/bin
mkdir -p $HOME/.local/share/android
cd $ANDROID_HOME
mkdir cmdline-tools
cd cmdline-tools
(get cmdline-tools from https://developer.android.com/studio#command-line-tools-only)
(unzip it)
(rename it to "latest")
sdkmanager --licenses
sdkmanager "platforms;android-ZZ"
(making build directory)
mkdir -p .build/{gen,obj/{dex,java},bin}
(compile resources)
aapt2 compile -o .build/gen --dir res/
(linking resources)
aapt2 link -I $ANDROID_HOME/platforms/android-ZZ/android.jar --java .build/obj/java --manifest AndroidManifest.xml -o .build/bin/app-unsigned.apk .build/gen/*.flat
(Java to JVM bytecode)
javac --release 17 -cp $ANDROID_HOME/platforms/android-ZZ/android.jar -d .build/obj/java java/com/rplc/sample_app/MainActivity.java .build/obj/java/com/rplc/sample_app/R.java
(JVM bytecode to Dalvik bytecode)
d8 --lib $ANDROID_HOME/platforms/android-ZZ/android.jar --output .build/obj/dex/ .build/obj/java/com/rplc/sample_app/*.class
(package Dalvik bytecode to the unsigned apk)
zip -uj .build/bin/app-unsigned.apk .build/obj/dex/*.dex
(align the apk for optimization)
zipalign -p 4 .build/bin/app-unsigned.apk .build/bin/app-aligned.apk
(generate a keystore key)
keytool -genkeypair -keystore debug.keystore -alias debugkey -keyalg RSA -keysize 2048 -validity 10000
(sign the apk)
apksigner sign --ks debug.keystore --ks-key-alias debugkey --out app.apk .build/bin/app-aligned.apk
(mv the apk to the shared storage or use adb install to install it directly)
Note: -YY- is the OpenJDK version.
Note: -ZZ is the Android SDK version you want to use, as of
today, AAPT2 from Termux Packages repository can only support maximum
of version 34.
Note: any text inside () is only for description, not an
actual command.
Note: this process is for debug build, you might need to change several command for a release build.
This repository is licensed under MIT No Attribution. so that you can use this as a basic template without rewriting bunch of basic things for your own app.