Files
d2r-mobile/dm/android/app/build_apk.sh
T
shenleiandClaude Opus 5.5 3c25cd89fc Android: move the shell to dm/android and the Vulkan backend to dm/gfx/vulkan
Mirror the iOS layout instead of nesting Android inside dm/host:
- dm/android/app       GameActivity app (manifest, java, res, build_apk.sh)
- dm/android/Sources   front_app.c, touch_app.c, front_headless.c
- dm/android/Makefile  entry point (apk / lib / install / headless / tests);
                       rules in build.mk (was dm/host/Makefile.android),
                       run with dm/host as cwd; outputs in dm/android/build/
- dm/android/tests     t_vk_perf
- dm/gfx/vulkan        nvn_vk.c and friends, next to the Metal backend

Only include paths, build paths and docs change; no code changes.
The Mac / iOS source lists do not pick up gfx/vulkan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 16:59:36 +09:00

51 lines
3.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# Package build/app/libd2r.so + GameActivity into a debug-signed APK, without Gradle.
# make -C dm/android (= build libd2r.so, then this script)
# Env: ANDROID_SDK (default ~/Library/Android/sdk), BUILD_TOOLS (35.0.0), PLATFORM (android-33),
# JAVA_HOME (default: Android Studio's bundled JBR), KEYSTORE (default ~/.android/debug.keystore).
set -eu
here=$(cd "$(dirname "$0")" && pwd)
out=$(cd "$here/.." && pwd)/build/app
sdk=${ANDROID_SDK:-$HOME/Library/Android/sdk}
bt=$sdk/build-tools/${BUILD_TOOLS:-35.0.0}
jar=$sdk/platforms/${PLATFORM:-android-33}/android.jar
jh=${JAVA_HOME:-"/Applications/Android Studio.app/Contents/jbr/Contents/Home"}
ks=${KEYSTORE:-$HOME/.android/debug.keystore}
so=$out/libd2r.so
[ -f "$so" ] || { echo "missing $so (build with APP=1 first)" >&2; exit 1; }
[ -f "$jar" ] || { echo "missing $jar" >&2; exit 1; }
[ -x "$jh/bin/javac" ] || { echo "no javac at $jh (set JAVA_HOME to JDK 11+)" >&2; exit 1; }
w=$out/apk
rm -rf "$w"; mkdir -p "$w/classes" "$w/dex" "$w/lib/arm64-v8a"
"$jh/bin/javac" -nowarn --release 11 -classpath "$jar" -d "$w/classes" \
$(find "$here/java" -name '*.java')
PATH="$jh/bin:$PATH" "$bt/d8" --release --min-api 29 --lib "$jar" --output "$w/dex" \
$(find "$w/classes" -name '*.class')
# 触屏 HUD 素材(从玩家自己的游戏文件生成,不进仓库):TouchArt/ = ios/tools/native_art/generate.py,hud_v4_ui/ = ios/tools/gen_hud_v4.py,mapgoal/ = ios/tools/gen_map_goal_art.py
# Touch HUD assets (generated from the player's own game files, not in the repo): TouchArt/ = ios/tools/native_art/generate.py, hud_v4_ui/ = ios/tools/gen_hud_v4.py, mapgoal/ = ios/tools/gen_map_goal_art.py
ios=$(cd "$here/../../ios" && pwd)
mkdir -p "$w/assets/TouchArt"
cp "$ios"/Sources/TouchArt/*.png "$w/assets/TouchArt/" 2>/dev/null || echo "warning: no TouchArt pngs (run ios/tools/gen_assets.py)" >&2
if [ -d "$ios/Gen/assets/NativeHUD/v4/hud_v4_ui" ]; then cp -R "$ios/Gen/assets/NativeHUD/v4/hud_v4_ui" "$w/assets/"
else echo "warning: no hud_v4_ui (run ios/tools/gen_assets.py)" >&2; fi
if [ -d "$ios/Gen/assets/NativeHUD/mapgoal" ]; then rm -rf "$w/assets/mapgoal"; cp -R "$ios/Gen/assets/NativeHUD/mapgoal" "$w/assets/mapgoal" # 小地图任务终点 = ios/tools/gen_map_goal_art.py | minimap quest goals = ios/tools/gen_map_goal_art.py
else echo "warning: no mapgoal (run ios/tools/gen_assets.py)" >&2; fi
# 资源只有启动图标(res/:自适应图标,图同 iOS AppIcon1024.png)| The only resource is the launcher icon (res/: adaptive icon, same art as iOS AppIcon1024.png)
"$bt/aapt2" compile --dir "$here/res" -o "$w/res.zip"
"$bt/aapt2" link -o "$w/base.apk" --manifest "$here/AndroidManifest.xml" -I "$jar" \
--min-sdk-version 29 --target-sdk-version 33 -A "$w/assets" -R "$w/res.zip" --auto-add-overlay
cp "$so" "$w/lib/arm64-v8a/libd2r.so"
(cd "$w/dex" && zip -q -X "$w/base.apk" classes.dex)
# Native libs stored uncompressed so they stay page-aligned for zipalign -P.
(cd "$w" && zip -q -X -0 base.apk lib/arm64-v8a/libd2r.so)
"$bt/zipalign" -f -P 16 4 "$w/base.apk" "$w/aligned.apk"
PATH="$jh/bin:$PATH" "$bt/apksigner" sign --ks "$ks" --ks-pass pass:android \
--ks-key-alias androiddebugkey --key-pass pass:android \
--out "$out/d2r.apk" "$w/aligned.apk"
echo "$out/d2r.apk"