Compile an Android app without Android Studio

Last updated: 2023-05-08

This guide assumes you're using Debian 11 and have root access to your computer.

Installing the Android SDK and its missing pieces

sudo apt install android-sdk default-jre

We need to manually download and install sdkmanager (because Debian doesn't package it in stable for some braindead reason):

cd /tmp
wget https://ftp.us.debian.org/debian/pool/main/s/sdkmanager/sdkmanager_0.6.4-1_all.deb
sudo dpkg -i /tmp/sdkmanager_0.6.4-1_all.deb
sudo apt install -f
			

 

Accepting the Android SDK licenses

Gradle will refuse to run if you don't have these accepted beforehand. You only need to do this once.

sudo chown -R YourUsername /usr/lib/android-sdk
sdkmanager --licenses
			

If you get a permission error concerning /opt, run the following and then try running sdkmanager again:

sudo mkdir /opt/android-sdk
sudo chown -R YourUsername /opt/android-sdk
			

sdkmanager is buggy as hell, so you will need to run it multiple times to set all the licenses to "accepted".

 

Telling Gradle where the Android SDK is

export ANDROID_HOME=/usr/lib/android-sdk

We recommend adding this as the last line of your shell config (ex. ~/.bashrc) so that you don't have to retype this every time you want to recompile something.

For the Fish shell, add the following to ~/.config/fish/config.fish:

set ANDROID_HOME /usr/lib/android-sdk
export ANDROID_HOME
			

 

Generating the signing key

keytool -genkey -alias youralias -keyalg RSA -keystore /path/to/where/you/want/to/keep/the/keys.jks

Keep your keystore safe. If you lose it and have to generate a new one, your app users will not be able to properly upgrade. They would have to export their data, uninstall the old app, and then install the new one. The only way around this is for your users to root their devices and disable signature verification, which is a massive security risk if said users don't know what they're doing.

 

Compiling the app

cd /path/to/source/code
./gradlew build
apksigner sign --ks /path/to/keystore.jks app/build/outputs/apk/release/app-release-unsigned.apk
			

If this is the first time you are running the Gradle wrapper, it will automatically download Gradle (which is at least a hundred megabytes large).

The actual path to the unsigned APK may be different depending on how the app you want to compile is structured.


made with <3 by your friends at Dead End Shrine Online
CC BY-NC-SA 4.0 © Lethe Beltane