Skip to content

Instantly share code, notes, and snippets.

@tdwong
Forked from authmane512/build.sh
Last active June 29, 2021 17:39
Show Gist options
  • Save tdwong/59d958dd3b27d0ab870140ac093c46cf to your computer and use it in GitHub Desktop.
Save tdwong/59d958dd3b27d0ab870140ac093c46cf to your computer and use it in GitHub Desktop.
Sample build script to create Android app from command line
#!/bin/bash
set -e
AAPT="/path/to/android-sdk/build-tools/23.0.3/aapt"
DX="/path/to/android-sdk/build-tools/23.0.3/dx"
ZIPALIGN="/path/to/android-sdk/build-tools/23.0.3/zipalign"
APKSIGNER="/path/to/android-sdk/build-tools/26.0.1/apksigner" # /!\ version 26
PLATFORM="/path/to/android-sdk/platforms/android-19/android.jar"
echo "Cleaning..."
rm -rf obj/*
rm -rf src/com/example/helloandroid/R.java
echo "Generating R.java file..."
$AAPT package -f -m -J src -M AndroidManifest.xml -S res -I $PLATFORM
echo "Compiling..."
javac -d obj -classpath src -bootclasspath $PLATFORM -source 1.7 -target 1.7 src/com/example/helloandroid/MainActivity.java
javac -d obj -classpath src -bootclasspath $PLATFORM -source 1.7 -target 1.7 src/com/example/helloandroid/R.java
echo "Translating in Dalvik bytecode..."
$DX --dex --output=classes.dex obj
echo "Making APK..."
$AAPT package -f -m -F bin/hello.unaligned.apk -M AndroidManifest.xml -S res -I $PLATFORM
$AAPT add bin/hello.unaligned.apk classes.dex
echo "Aligning and signing APK..."
$APKSIGNER sign --ks mykey.keystore bin/hello.unaligned.apk
$ZIPALIGN -f 4 bin/hello.unaligned.apk bin/hello.apk
if [ "$1" == "test" ]; then
echo "Launching..."
adb install -r bin/hello.apk
adb shell am start -n com.example.helloandroid/.MainActivity
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment