diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 00000000..aaa824d4 --- /dev/null +++ b/android/.gitignore @@ -0,0 +1,5 @@ +.gradle/ +build/ +app/build/ +app/.cxx/ +local.properties diff --git a/android/README.md b/android/README.md new file mode 100644 index 00000000..8a7cf080 --- /dev/null +++ b/android/README.md @@ -0,0 +1,31 @@ +# AVA2 Android client + +Gradle project for the arm64-v8a APK: SDL3 `SDLActivity` + `libmain.so` (the client, with the +embedded CPython 2.7). The APK holds code only. Game data (`ymir work`, maps, sound, python-root, +`python27.zip`) lives in the app's external storage directory, see `push-assets.sh`. +Architecture and roadmap: `docs/MOBILE-ARCHITECTURE.md`. + +## Requirements + +- Android SDK with platform 35, NDK 27.2.12479018 and CMake 3.22.1 (`sdkmanager "ndk;27.2.12479018" "cmake;3.22.1"`) +- JDK 17+ (`brew install openjdk@21`; `build.sh` finds it automatically) +- The SDK checkout beside this repository (`../sdk`), as for the desktop build + +## Build + +```bash +android/build.sh # debug APK; installs and launches it when a phone is attached +android/build.sh release # release APK +android/build.sh deps # only build SDL3 + FreeType into build/android-deps +``` + +The first run downloads and builds SDL3 and FreeType once into `build/android-deps`. The SDL +Java sources are copied from the same SDL release so they always match `libSDL3.so`. The debug +APK compiles C++ as RelWithDebInfo; a Debug build is too slow to judge frame rate. + +Overrides: `ANDROID_HOME`, `ANDROID_NDK_HOME`, `JAVA_HOME`, `AVA2_SDK_ROOT`, `AVA2_SOURCE_DIR` +(CMake source tree to build instead of this checkout), `ADB_SERIAL`. + +Android Studio can open this directory after `android/build.sh deps` has run once. + +Logs: `adb logcat -s SDL SDL/APP AndroidRuntime DEBUG`. diff --git a/android/app/build.gradle b/android/app/build.gradle new file mode 100644 index 00000000..ebce5749 --- /dev/null +++ b/android/app/build.gradle @@ -0,0 +1,84 @@ +plugins { + id 'com.android.application' +} + +// android/build.sh passes these; the defaults let Android Studio reuse what `build.sh deps` built. +def repoRoot = file('../..').canonicalPath +// AVA2_SOURCE_DIR builds another checkout/mirror of this repository (e.g. one with local SDK shims). +def sourceDir = project.findProperty('AVA2_SOURCE_DIR') ?: repoRoot +def depsPrefix = project.findProperty('AVA2_DEPS_PREFIX') ?: "${repoRoot}/build/android-deps/prefix-arm64-v8a" +def sdlJava = project.findProperty('AVA2_SDL_JAVA') ?: "${repoRoot}/build/android-deps/sdl-java" +def cmakeArgs = [ + "-DAVA2_BUILD_HOST=ON", "-DAVA2_EMBED_PYTHON=ON", "-DBUILD_TESTING=OFF", + "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON", + "-DSDL3_DIR=${depsPrefix}/lib/cmake/SDL3", "-DCMAKE_FIND_ROOT_PATH=${depsPrefix}", +] +if (project.hasProperty('AVA2_SDK_ROOT')) cmakeArgs << "-DAVA2_SDK_ROOT=${project.property('AVA2_SDK_ROOT')}" + +android { + namespace 'com.metin2.ava2' + compileSdk 35 + ndkVersion project.findProperty('AVA2_NDK_VERSION') ?: '27.2.12479018' + + defaultConfig { + applicationId "com.metin2.ava2" + minSdk 26 + targetSdk 35 + versionCode 1 + versionName "0.1.0" + + ndk { + abiFilters 'arm64-v8a' + } + + externalNativeBuild { + cmake { + arguments(*cmakeArgs) + targets 'main' + } + } + } + + buildTypes { + release { + minifyEnabled false + } + debug { + debuggable true + jniDebuggable true + // Debug-built C++ is too slow to judge frame rate on a phone. + externalNativeBuild { cmake { arguments "-DCMAKE_BUILD_TYPE=RelWithDebInfo" } } + } + } + + externalNativeBuild { + cmake { + path file("${sourceDir}/CMakeLists.txt") + version project.findProperty('AVA2_CMAKE_VERSION') ?: '3.22.1' + } + } + + sourceSets { + main { + java.srcDirs += [sdlJava] + jniLibs.srcDirs += ["${depsPrefix}/lib-jni"] + } + } + + packagingOptions { + jniLibs { + useLegacyPackaging = false + } + } + + lint { + abortOnError false + } +} + +// libSDL3.so is a prebuilt dependency: stage it in the jniLibs layout AGP expects. +tasks.register('stageSdlLibrary', Copy) { + from "${depsPrefix}/lib/libSDL3.so" + into "${depsPrefix}/lib-jni/arm64-v8a" +} +preBuild.dependsOn stageSdlLibrary diff --git a/support/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml similarity index 56% rename from support/android/app/src/main/AndroidManifest.xml rename to android/app/src/main/AndroidManifest.xml index 92dff419..5ba0589c 100644 --- a/support/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,37 +1,38 @@ - + - - + + + + - - diff --git a/android/app/src/main/res/drawable/ic_launcher_background.xml b/android/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..9d631d45 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,4 @@ + + + + diff --git a/android/app/src/main/res/drawable/ic_launcher_foreground.xml b/android/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 00000000..33764af6 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 00000000..6d78b6b0 --- /dev/null +++ b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml new file mode 100644 index 00000000..d239316f --- /dev/null +++ b/android/app/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + + AVA2 + diff --git a/android/build.gradle b/android/build.gradle new file mode 100644 index 00000000..5b7ccba7 --- /dev/null +++ b/android/build.gradle @@ -0,0 +1,3 @@ +plugins { + id 'com.android.application' version '8.7.3' apply false +} diff --git a/android/build.sh b/android/build.sh new file mode 100755 index 00000000..ffde62e3 --- /dev/null +++ b/android/build.sh @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +# Builds the Android APK (arm64-v8a) and, when a device is attached, installs and launches it. +# +# android/build.sh debug APK (+ install/launch if `adb devices` lists a phone) +# android/build.sh release release APK (unsigned unless signing is configured) +# android/build.sh deps only (re)build the native dependencies +# +# Native dependencies (SDL3 + FreeType) are downloaded and built once into build/android-deps. +# Environment overrides: ANDROID_HOME, ANDROID_NDK_HOME, JAVA_HOME, AVA2_SDK_ROOT, AVA2_SOURCE_DIR +# (CMake source tree, default this checkout), ADB_SERIAL. +set -euo pipefail + +HERE="$(cd "$(dirname "$0")" && pwd)" +ROOT="$(cd "$HERE/.." && pwd)" +MODE="${1:-debug}" + +SDL_VERSION=3.4.16 +FREETYPE_VERSION=2.13.3 +NDK_VERSION=27.2.12479018 +CMAKE_VERSION=3.22.1 +API_LEVEL=26 +ABI=arm64-v8a + +export ANDROID_HOME="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$HOME/Library/Android/sdk}}" +export ANDROID_NDK_HOME="${ANDROID_NDK_HOME:-$ANDROID_HOME/ndk/$NDK_VERSION}" +if [[ -z "${JAVA_HOME:-}" ]] || ! "$JAVA_HOME/bin/java" -version 2>&1 | grep -qE 'version "(1[7-9]|2[0-9])'; then + for candidate in /opt/homebrew/opt/openjdk@21 /opt/homebrew/opt/openjdk@17 /usr/local/opt/openjdk@21 \ + "/Applications/Android Studio.app/Contents/jbr/Contents/Home"; do + [[ -x "$candidate/bin/java" ]] && { export JAVA_HOME="$candidate"; break; } + done +fi +[[ -d "$ANDROID_HOME" ]] || { echo "Android SDK not found (set ANDROID_HOME)"; exit 1; } +[[ -d "$ANDROID_NDK_HOME" ]] || { echo "NDK $NDK_VERSION not found (sdkmanager 'ndk;$NDK_VERSION')"; exit 1; } +[[ -x "${JAVA_HOME:-}/bin/java" ]] || { echo "JDK 17+ not found (brew install openjdk@21 or set JAVA_HOME)"; exit 1; } + +CMAKE="$ANDROID_HOME/cmake/$CMAKE_VERSION/bin/cmake" +NINJA="$ANDROID_HOME/cmake/$CMAKE_VERSION/bin/ninja" +[[ -x "$CMAKE" ]] || { echo "CMake $CMAKE_VERSION not found (sdkmanager 'cmake;$CMAKE_VERSION')"; exit 1; } + +DEPS="$ROOT/build/android-deps" +PREFIX="$DEPS/prefix-$ABI" +mkdir -p "$DEPS/src" + +fetch() { # url file + [[ -f "$DEPS/src/$2" ]] && return + curl -fL --retry 3 -o "$DEPS/src/$2.part" "$1" || { echo "download failed: $1"; exit 1; } + mv -f "$DEPS/src/$2.part" "$DEPS/src/$2" +} + +cmake_dep() { # source-dir build-dir extra-args... + local src="$1" bld="$2"; shift 2 + "$CMAKE" -S "$src" -B "$bld" -G Ninja -DCMAKE_MAKE_PROGRAM="$NINJA" \ + -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ + -DANDROID_ABI=$ABI -DANDROID_PLATFORM=android-$API_LEVEL -DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON \ + -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$PREFIX" -DCMAKE_POSITION_INDEPENDENT_CODE=ON "$@" + "$CMAKE" --build "$bld" + "$CMAKE" --install "$bld" +} + +build_deps() { + if [[ ! -f "$PREFIX/lib/libSDL3.so" ]]; then + fetch "https://github.com/libsdl-org/SDL/releases/download/release-$SDL_VERSION/SDL3-$SDL_VERSION.tar.gz" "SDL3-$SDL_VERSION.tar.gz" + rm -rf "$DEPS/src/SDL3-$SDL_VERSION" && tar -xzf "$DEPS/src/SDL3-$SDL_VERSION.tar.gz" -C "$DEPS/src" + cmake_dep "$DEPS/src/SDL3-$SDL_VERSION" "$DEPS/build-sdl3-$ABI" \ + -DSDL_SHARED=ON -DSDL_STATIC=OFF -DSDL_TEST_LIBRARY=OFF -DSDL_TESTS=OFF -DSDL_EXAMPLES=OFF + fi + if [[ ! -f "$PREFIX/lib/libfreetype.a" ]]; then + fetch "https://download.savannah.gnu.org/releases/freetype/freetype-$FREETYPE_VERSION.tar.xz" "freetype-$FREETYPE_VERSION.tar.xz" + rm -rf "$DEPS/src/freetype-$FREETYPE_VERSION" && tar -xJf "$DEPS/src/freetype-$FREETYPE_VERSION.tar.xz" -C "$DEPS/src" + cmake_dep "$DEPS/src/freetype-$FREETYPE_VERSION" "$DEPS/build-freetype-$ABI" -DBUILD_SHARED_LIBS=OFF \ + -DFT_DISABLE_ZLIB=ON -DFT_DISABLE_BZIP2=ON -DFT_DISABLE_PNG=ON -DFT_DISABLE_HARFBUZZ=ON -DFT_DISABLE_BROTLI=ON + fi + # SDLActivity and friends must match the native libSDL3.so exactly. + rm -rf "$DEPS/sdl-java" && mkdir -p "$DEPS/sdl-java" + cp -R "$DEPS/src/SDL3-$SDL_VERSION/android-project/app/src/main/java/org" "$DEPS/sdl-java/" +} + +build_deps +[[ "$MODE" == deps ]] && exit 0 + +cd "$HERE" +GRADLE_ARGS=(-PAVA2_DEPS_PREFIX="$PREFIX" -PAVA2_SDL_JAVA="$DEPS/sdl-java" -PAVA2_CMAKE_VERSION=$CMAKE_VERSION + -PAVA2_NDK_VERSION=$NDK_VERSION) +[[ -n "${AVA2_SDK_ROOT:-}" ]] && GRADLE_ARGS+=(-PAVA2_SDK_ROOT="$AVA2_SDK_ROOT") +[[ -n "${AVA2_SOURCE_DIR:-}" ]] && GRADLE_ARGS+=(-PAVA2_SOURCE_DIR="$AVA2_SOURCE_DIR") +if [[ "$MODE" == release ]]; then + ./gradlew "${GRADLE_ARGS[@]}" assembleRelease + ls -l app/build/outputs/apk/release/*.apk + exit 0 +fi +./gradlew "${GRADLE_ARGS[@]}" assembleDebug +APK="$HERE/app/build/outputs/apk/debug/app-debug.apk" +ls -l "$APK" + +ADB="$ANDROID_HOME/platform-tools/adb"; command -v adb >/dev/null && ADB="$(command -v adb)" +[[ -n "${ADB_SERIAL:-}" ]] && ADB="$ADB -s $ADB_SERIAL" +if $ADB get-state >/dev/null 2>&1; then + $ADB install -r -d "$APK" + $ADB shell am start -n com.metin2.ava2/org.libsdl.app.SDLActivity + echo "Launched. Logs: $ADB logcat -s SDL SDL/APP AVA2 DEBUG AndroidRuntime" +else + echo "No device attached; APK not installed." +fi diff --git a/android/gradle.properties b/android/gradle.properties new file mode 100644 index 00000000..5d2c983f --- /dev/null +++ b/android/gradle.properties @@ -0,0 +1,2 @@ +org.gradle.jvmargs=-Xmx4g -Dfile.encoding=UTF-8 +android.nonTransitiveRClass=true diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..a4b76b95 Binary files /dev/null and b/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..cea7a793 --- /dev/null +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/android/gradlew b/android/gradlew new file mode 100755 index 00000000..f5feea6d --- /dev/null +++ b/android/gradlew @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/android/gradlew.bat b/android/gradlew.bat new file mode 100644 index 00000000..9b42019c --- /dev/null +++ b/android/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/support/android/settings.gradle b/android/settings.gradle similarity index 100% rename from support/android/settings.gradle rename to android/settings.gradle diff --git a/support/android/README.md b/support/android/README.md deleted file mode 100644 index c949a829..00000000 --- a/support/android/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# AVA2 Android Client Build & Packaging Guide - -This directory contains the standard Android Gradle and NDK packaging setup for the AVA2 cross-platform Metin2 client. - -## Requirements -- Android SDK (API 34) -- Android NDK (r25c or newer) -- CMake 3.22.1+ -- Gradle 8.2+ - -## Architecture -- Native Target: `libmain.so` (arm64-v8a) -- Host Environment: SDL3 `SDLActivity` + Embedded CPython 2.7.18 + Metal/Vulkan/GLES3 backend -- Assets: Packed Metin2 assets in `app/src/main/assets/` - -## Build Command -```bash -# Configure and build APK -cd support/android -./gradlew assembleDebug -# or Release -./gradlew assembleRelease -``` diff --git a/support/android/app/build.gradle b/support/android/app/build.gradle deleted file mode 100644 index 577ad5ef..00000000 --- a/support/android/app/build.gradle +++ /dev/null @@ -1,61 +0,0 @@ -plugins { - id 'com.android.application' -} - -android { - namespace 'com.metin2.ava2' - compileSdk 34 - - defaultConfig { - applicationId "com.metin2.ava2" - minSdk 26 - targetSdk 34 - versionCode 1 - versionName "1.0.0" - - ndk { - abiFilters 'arm64-v8a' - } - - externalNativeBuild { - cmake { - arguments "-DAVA2_BUILD_HOST=ON", "-DAVA2_EMBED_PYTHON=ON", "-DANDROID_STL=c++_shared" - cppFlags "-std=c++20" - } - } - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - debug { - debuggable true - jniDebuggable true - } - } - - externalNativeBuild { - cmake { - path file('../../../CMakeLists.txt') - version '3.22.1+' - } - } - - sourceSets { - main { - assets.srcDirs = ['src/main/assets'] - } - } - - packagingOptions { - jniLibs { - useLegacyPackaging = true - } - } -} - -dependencies { - // SDL3 native runtime -}