This commit is contained in:
2026-08-16 03:48:57 -03:00
parent 5621de243a
commit c02b36c83d
48 changed files with 5398 additions and 2221 deletions
+71 -19
View File
@@ -2,22 +2,74 @@
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
SDK="${ANDROID_SDK_ROOT:-${ANDROID_HOME:-}}"
[[ -n "$SDK" ]] || { echo "Set ANDROID_SDK_ROOT" >&2; exit 1; }
BUILD_TOOLS="${BUILD_TOOLS:-35.0.0}"; PLATFORM="${PLATFORM:-android-35}"
if [[ ! -d "$SDK/build-tools/$BUILD_TOOLS" ]]; then BUILD_TOOLS="$(find "$SDK/build-tools" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort -V | tail -1)"; fi
if [[ ! -f "$SDK/platforms/$PLATFORM/android.jar" ]]; then PLATFORM="$(find "$SDK/platforms" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort -V | tail -1)"; fi
BT="$SDK/build-tools/$BUILD_TOOLS"; AJ="$SDK/platforms/$PLATFORM/android.jar"
for tool in aapt d8 apksigner; do [[ -x "$BT/$tool" ]] || { echo "Missing $BT/$tool" >&2; exit 1; }; done
CORE="$ROOT/lib/arm64-v8a/libdragontcp_vpn.so"; [[ -f "$CORE" ]] || { echo "Run ../build_core.sh first" >&2; exit 1; }
B="$ROOT/build"; rm -rf "$B"; mkdir -p "$B/classes" "$B/dex"
"$BT/aapt" package -f -M "$ROOT/AndroidManifest.xml" -S "$ROOT/res" -I "$AJ" -F "$B/resources.ap_"
javac -source 8 -target 8 -classpath "$AJ" -d "$B/classes" $(find "$ROOT/src" -name '*.java' -print)
"$BT/d8" --lib "$AJ" --min-api 29 --output "$B/dex" $(find "$B/classes" -name '*.class' -print)
cp "$B/resources.ap_" "$B/DragonTCP-VPN-unsigned.apk"
(cd "$B/dex" && zip -q "$B/DragonTCP-VPN-unsigned.apk" classes.dex)
(cd "$ROOT" && zip -q -r "$B/DragonTCP-VPN-unsigned.apk" lib)
KEYSTORE="$ROOT/dragontcp-debug.jks"
if [[ ! -f "$KEYSTORE" ]]; then keytool -genkeypair -keystore "$KEYSTORE" -storepass dragontcp -keypass dragontcp -alias dragontcp -keyalg RSA -keysize 2048 -validity 10000 -dname "CN=DragonTCP VPN,O=DragonTCP,C=US"; fi
"$BT/apksigner" sign --ks "$KEYSTORE" --ks-pass pass:dragontcp --key-pass pass:dragontcp --out "$B/DragonTCP-VPN.apk" "$B/DragonTCP-VPN-unsigned.apk"
"$BT/apksigner" verify --verbose "$B/DragonTCP-VPN.apk"
echo "Built APK: $B/DragonTCP-VPN.apk"
KOTLIN_HOME="${KOTLIN_HOME:-$HOME/.sdkman/candidates/kotlin/current}"
BUILD_TOOLS="${BUILD_TOOLS:-35.0.0}"
PLATFORM="${PLATFORM:-android-35}"
[[ -n "$SDK" ]] || { echo "Set ANDROID_SDK_ROOT (or ANDROID_HOME)." >&2; exit 1; }
[[ -d "$KOTLIN_HOME" ]] || { echo "Set KOTLIN_HOME to a Kotlin compiler distribution." >&2; exit 1; }
BT="$SDK/build-tools/$BUILD_TOOLS"
AJ="$SDK/platforms/$PLATFORM/android.jar"
if [[ ! -d "$BT" ]]; then
BUILD_TOOLS="$(find "$SDK/build-tools" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort -V | tail -1)"
BT="$SDK/build-tools/$BUILD_TOOLS"
fi
if [[ ! -f "$AJ" ]]; then
PLATFORM="$(find "$SDK/platforms" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort -V | tail -1)"
AJ="$SDK/platforms/$PLATFORM/android.jar"
fi
for tool in aapt d8 apksigner; do
[[ -x "$BT/$tool" ]] || { echo "Missing $BT/$tool" >&2; exit 1; }
done
[[ -f "$AJ" ]] || { echo "Android platform android.jar not found" >&2; exit 1; }
[[ -x "$KOTLIN_HOME/bin/kotlinc" ]] || { echo "kotlinc not found under KOTLIN_HOME" >&2; exit 1; }
CORO="$KOTLIN_HOME/lib/kotlinx-coroutines-core-jvm.jar"
[[ -f "$CORO" ]] || { echo "Missing $CORO (install a Kotlin distribution that includes kotlinx-coroutines-core-jvm.jar)" >&2; exit 1; }
[[ -f "$ROOT/lib/arm64-v8a/libdragontcp_client.so" ]] || { echo "Run ../build_core.sh first" >&2; exit 1; }
B="$ROOT/build"
rm -rf "$B"
mkdir -p "$B/kclasses" "$B/jclasses" "$B/dex"
echo "[apk] Resources..."
"$BT/aapt" package -f -M "$ROOT/AndroidManifest.xml" -S "$ROOT/res" -A "$ROOT/assets" -I "$AJ" -F "$B/resources.ap_"
echo "[apk] Kotlin TUN adapter..."
CP="$AJ:$CORO"
find "$ROOT/src" -name '*.kt' -print > "$B/kotlin-sources.txt"
"$KOTLIN_HOME/bin/kotlinc" -jvm-target 1.8 -classpath "$CP" -d "$B/kclasses" @"$B/kotlin-sources.txt"
echo "[apk] Java UI/service..."
JCP="$CP:$B/kclasses:$KOTLIN_HOME/lib/kotlin-stdlib.jar:$KOTLIN_HOME/lib/kotlin-stdlib-jdk7.jar:$KOTLIN_HOME/lib/kotlin-stdlib-jdk8.jar"
javac -source 8 -target 8 -classpath "$JCP" -d "$B/jclasses" $(find "$ROOT/src" -name '*.java' -print)
jar cf "$B/kclasses.jar" -C "$B/kclasses" .
jar cf "$B/jclasses.jar" -C "$B/jclasses" .
echo "[apk] DEX..."
"$BT/d8" --lib "$AJ" --min-api 29 --output "$B/dex" \
"$B/kclasses.jar" "$B/jclasses.jar" \
"$KOTLIN_HOME/lib/kotlin-stdlib.jar" \
"$KOTLIN_HOME/lib/kotlin-stdlib-jdk7.jar" \
"$KOTLIN_HOME/lib/kotlin-stdlib-jdk8.jar" \
"$CORO"
cp "$B/resources.ap_" "$B/DragonTCP-LiteVPN-unsigned.apk"
(cd "$B/dex" && zip -q "$B/DragonTCP-LiteVPN-unsigned.apk" classes*.dex)
(cd "$ROOT" && zip -q -r "$B/DragonTCP-LiteVPN-unsigned.apk" lib)
KEYSTORE="${KEYSTORE:-$ROOT/dragontcp-lite-debug.jks}"
KS_PASS="${KS_PASS:-dragontcp}"
KEY_ALIAS="${KEY_ALIAS:-dragontcp}"
KEY_PASS="${KEY_PASS:-dragontcp}"
if [[ ! -f "$KEYSTORE" ]]; then
keytool -genkeypair -keystore "$KEYSTORE" -storepass "$KS_PASS" -keypass "$KEY_PASS" \
-alias "$KEY_ALIAS" -keyalg RSA -keysize 2048 -validity 10000 \
-dname 'CN=DragonTCP Lite,O=DragonTCP,C=US'
fi
"$BT/apksigner" sign --ks "$KEYSTORE" --ks-pass "pass:$KS_PASS" --key-pass "pass:$KEY_PASS" \
--out "$B/DragonTCP-LiteVPN-arm64.apk" "$B/DragonTCP-LiteVPN-unsigned.apk"
"$BT/apksigner" verify --verbose "$B/DragonTCP-LiteVPN-arm64.apk"
echo "APK: $B/DragonTCP-LiteVPN-arm64.apk"