Init
This commit is contained in:
Executable
+60
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build portal-capability-test.apk from src/ with the plain SDK toolchain
|
||||
# (javac -> d8 -> aapt2 -> zipalign -> apksigner). No Gradle.
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
SDK="$HOME/Library/Android/sdk"
|
||||
PLATFORM="$SDK/platforms/android-35/android.jar"
|
||||
BT="$SDK/build-tools/37.0.0"
|
||||
OUT=portal-capability-test.apk
|
||||
|
||||
rm -rf build/classes build/apk build/compiled-res.zip build/unaligned.apk build/aligned.apk
|
||||
mkdir -p build/classes build/apk
|
||||
|
||||
echo "== kotlinc =="
|
||||
KOTLIN="/Applications/Android Studio.app/Contents/plugins/Kotlin/kotlinc/bin/kotlinc"
|
||||
KOTLIN_LIB="/Applications/Android Studio.app/Contents/plugins/Kotlin/kotlinc/lib"
|
||||
KOTLIN_STDLIB="$KOTLIN_LIB/kotlin-stdlib-jdk8.jar"
|
||||
KOTLIN_STDLIB_BASE="$KOTLIN_LIB/kotlin-stdlib.jar"
|
||||
COROUTINES_CORE="$KOTLIN_LIB/kotlinx-coroutines-core-jvm.jar"
|
||||
# Android Main dispatcher (optional at compile; needed at runtime for Dispatchers.Main)
|
||||
COROUTINES_ANDROID=$(find "$HOME/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-android" -name 'kotlinx-coroutines-android-*.jar' 2>/dev/null | sort -V | tail -1)
|
||||
if [[ -z "${COROUTINES_ANDROID}" || ! -f "${COROUTINES_ANDROID}" ]]; then
|
||||
echo "error: kotlinx-coroutines-android jar not found under ~/.gradle/caches" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
KT_CP="$PLATFORM:$COROUTINES_CORE:$COROUTINES_ANDROID"
|
||||
"$KOTLIN" -cp "$KT_CP" -d build/kotlin.jar \
|
||||
$(find src smartcamera/src -name '*.kt')
|
||||
|
||||
echo "== javac =="
|
||||
javac --release 8 -classpath "$PLATFORM:build/kotlin.jar" \
|
||||
-d build/classes $(find src -name '*.java')
|
||||
|
||||
echo "== d8 =="
|
||||
"$BT/d8" --lib "$PLATFORM" --min-api 28 --output build/apk \
|
||||
$(find build/classes -name '*.class') build/kotlin.jar \
|
||||
"$KOTLIN_STDLIB" "$KOTLIN_STDLIB_BASE" "$COROUTINES_CORE" "$COROUTINES_ANDROID"
|
||||
|
||||
echo "== aapt2 compile+link =="
|
||||
"$BT/aapt2" compile --dir res -o build/compiled-res.zip
|
||||
"$BT/aapt2" link -o build/unaligned.apk \
|
||||
-I "$PLATFORM" \
|
||||
--manifest AndroidManifest.xml \
|
||||
--java src \
|
||||
build/compiled-res.zip
|
||||
|
||||
# aapt2 --java regenerates R.java under src/; we don't use R, ignore it.
|
||||
# Repack dex into the apk.
|
||||
cp build/unaligned.apk build/withdex.apk
|
||||
( cd build/apk && zip -q -u ../withdex.apk *.dex )
|
||||
|
||||
echo "== zipalign + sign =="
|
||||
"$BT/zipalign" -f 4 build/withdex.apk build/aligned.apk
|
||||
"$BT/apksigner" sign --ks ~/.android/debug.keystore --ks-pass pass:android \
|
||||
--out "$OUT" build/aligned.apk
|
||||
|
||||
echo "built $OUT"
|
||||
Reference in New Issue
Block a user