Skip to content

Instantly share code, notes, and snippets.

@tmatz
Last active June 21, 2026 07:28
Show Gist options
  • Select an option

  • Save tmatz/817bf03433e059bf89c63dc33f286ccb to your computer and use it in GitHub Desktop.

Select an option

Save tmatz/817bf03433e059bf89c63dc33f286ccb to your computer and use it in GitHub Desktop.
Build android app on termux

Build android app on termux

1. install termux

install termux from F-Droid.

2. setup termux

apt update
apt upgrade
# source.list changed
apt update
termux-setup-storage

3. install ubuntu

apt install git wget proot
git clone https://github.com/MFDGaming/ubuntu-in-termux.git
cd ubuntu-in-termux
# install ubuntu
bash ubuntu.sh -y
# fix PATH order
sed -Ei 's|(:/bin)(:/usr/bin):|\2\1:|' startubuntu.sh
# start
./startubuntu.sh

4. install packages for build

Now, in ubuntu.

apt update
apt upgrade
apt install default-jdk-headless openjdk-8-jdk-headless unzip aapt2

5. install android cmdline-tools and platforms

Download Android Command Line Tools for Linux from https://developer.android.com/studio

cd ~
unzip /sdcard/Download/commandlinetools-linux-9477386_latest.zip
export ANDROID_HOME=$HOME/android/sdk
mkdir -p $ANDROID_HOME/cmdline-tools
mv cmdline-tools $ANDROID_HOME/cmdline-tools/latest
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin
# just for fix broken dependencies
JAVA_OPTS=-Dos.arch=amd64 sdkmanager emulator
# install target platforms
sdkmanager 'platforms;android-26'

5. replace aapt2

cd project-dir
echo "sdk.dir=$ANDROID_HOME" > local.properties
alias gradlew='JAVA_HOME=/usr/lib/jvm/java-8-openjdk-arm64 bash ./gradlew'
# first build should fail. it is for downloading aapt2-*-linux.jar
gradlew
# replace aapt2 binary for arm64
find ~/.gradle -name 'aapt2-*-linux.jar' -type f | xargs -I{} jar -u -f {} -C /usr/bin aapt2

6. build apk!

cd project-dir
gradlew
@hirkanloyal

Copy link
Copy Markdown

I managed to get Android APK builds working on an ARM64 Ubuntu PRoot environment (running on Android/Termux) and wanted to share what finally worked for me.

The root cause was that Google's SDK Build Tools ship an x86_64 aapt2 binary for Linux. On ARM64 this fails with:

cannot execute: required file not found

or AGP resource-linking failures because the bundled aapt2 cannot run.

I first tried the Debian ARM64 aapt2 package:

/usr/lib/android-sdk/build-tools/debian/aapt2

but it was too old and failed against modern Android SDK platforms (Android 36 in my case) with errors like:

LoadedArsc.cpp:94 RES_TABLE_TYPE_TYPE entry offsets overlap actual entry data
Failed to load resources table in APK 'android.jar'

The solution was:

  1. Download a modern ARM64 aapt2 binary from ReVanced:

https://github.com/ReVanced/aapt2/releases

I used:

aapt2-arm64-v8a

  1. Make it executable:

chmod +x ~/tools/aapt2

  1. Add the following to gradle.properties:

android.aapt2FromMavenOverride=/root/tools/aapt2

  1. If using Kotlin + Java 17, also make sure JVM targets match:

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlin {
jvmToolchain(17)
}

After switching from the old Debian aapt2 to the ReVanced ARM64 build, ./gradlew assembleDebug completed successfully and produced a working APK on ARM64 Ubuntu PRoot.

Hopefully this helps anyone trying to build Android apps natively on ARM64 Linux/Termux environments.

Tested on:

  • Termux
  • Ubuntu PRoot (ARM64)
  • OpenJDK 17
  • Gradle 9.6
  • Android Gradle Plugin 8.8.2
  • compileSdk 36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment