Skip to content

RandomPersonLikesCode/Android-App-Without-Gradle-In-Termux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Android App Development (Without Gradle) In Termux

Background

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.

Prerequisites

Primary Build Tools

  • OpenJDK (preferably OpenJDK 21, it can be higher)
  • AAPT2 (from Termux Packages repository)
  • D8 (from cmdline-tools)

Secondary Build Tools

  • Zipalign
  • Keytool
  • Apksigner

Environment Variables

  • $JAVA_HOME set to $PREFIX/lib/jvm/java-YY-openjdk
  • $ANDROID_HOME preferably set to $HOME/.local/share/android
  • $PATH set to $PATH:$ANDROID_HOME/cmdline-tools/latest/bin

Command Line Tools Setup

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"

Build Step

(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)

Notes

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.

License

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.

About

Guides to setup and building Android apps in Termux without the complexity of a build system

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages