draconisPW / PWMAngband

A free, multi-player roguelike dungeon exploration game based on Angband
35 stars 12 forks source link

Android SDL2 client #533

Closed s88100 closed 2 years ago

s88100 commented 2 years ago

Prepare the project

SDL2 https://www.libsdl.org/download-2.0.php Source Code: https://www.libsdl.org/release/SDL2-2.0.16.zip

SDL_ttf 2.0 https://www.libsdl.org/projects/SDL_ttf/ Source: https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.15.zip

SDL_image 2.0 https://www.libsdl.org/projects/SDL_image/ Source: https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.5.zip

SDL_mixer 2.0 https://www.libsdl.org/projects/SDL_mixer/ Source: https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.4.zip

Extract them, copy or symlink directory into: android/pwmangclient/jni/SDL2 android/pwmangclient/jni/SDL2_image android/pwmangclient/jni/SDL2_ttf android/pwmangclient/jni/SDL2_mixer

Copy or symlink pwmangband lib directory into pwmangband src/android/pwmangclient/src/main/assets/lib cd src/android ln -s ../../../../../../lib pwmangclient/src/main/assets/lib

Prepare gradle

https://www.higithub.com/ReimoSaar/repo/Guide-for-SDL2-SDL2_Image-and-Android-Studio https://blog.emptyq.net/a?ID=00004-29f2e9d6-d96d-498a-aceb-d79ceff86c26

Download and install Android Studio. https://developer.android.com/studio

Welcome to Android Studio New Project->Basic Activity, Next, Finish

Tools->SDK Manager Settings: Android SDK SDK Platforms: Android 12.0 (S) API Level 31 SDK Tools: Android SDK Build-Tools 31.0.0 NDK (Side by side) 21.4.7075529 Android SDK Command-line Tools 5.0 -Android Emulator 31.1.4 -Android SDK Platform-Tools 31.0.3

Tools->Device Manager->Create device: Galaxy Nexus API 30 Android 11.0 Google APIs x86 (Landscape)

Make Project File->Close Project

Welcome to Android Studio Import Project (Gradle, Eclipse ADT, etc.) PWMAngband-master/src/android Ok

File->Project Structure: Project: Android Gradle Plugin Version 7.1.0 Gradle Version 7.2

Make Project Run 'pwmangclient' Settings:Apps & notifications->PWMAngClient Permissions->ALLOWED: Files and Media to access the files '/storage/emulated/0/', '/sdcard/' http://www.estrongs.com/ ES File Explorer drag&drop copy or unzip files 'PWMAngband/lib' located in 'Downloads' folder to '/storage/emulated/0/PWMAngband/lib' or '/sdcard/PWMAngband/lib' launch PWMAngband

only 'x86' is build after recompilation to build all 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' I delete 'src/android/pwmangclient/build' folder

https://riptutorial.com/android/example/17614/how-to-log-in-ndk

#ifdef ON_ANDROID
#include <android/log.h>
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "PWMAngband", __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG  , "PWMAngband", __VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO   , "PWMAngband", __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN   , "PWMAngband", __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR  , "PWMAngband", __VA_ARGS__) 
#define LOG(...) __android_log_print(ANDROID_LOG_DEBUG  , "PWMAngband", __VA_ARGS__)
#endif

src/client/ui-init.c
init_stuff()
LOGD("configpath: %s", configpath);
LOGD("libpath: %s", libpath);
LOGD("datapath: %s", datapath);

Logcat:
org.pwmangband.pwmangclient D/PWMAngband: configpath: /storage/emulated/0/PWMAngband/lib/
org.pwmangband.pwmangclient D/PWMAngband: libpath: /storage/emulated/0/PWMAngband/lib/
org.pwmangband.pwmangclient D/PWMAngband: datapath: /storage/emulated/0/PWMAngband/lib/

Any files you put in the "app/src/main/assets" directory of your project directory will get bundled into the application package and you can load them using the standard functions in SDL_rwops.h.

define USE_SDL_RWOPS

I edited 'common/z-file.c' https://github.com/mangband/mangband/blob/develop/src/common/z-file.c src/common/h-basic.h

define DEFAULT_CONFIG_PATH "lib/"

define DEFAULT_DATA_PATH "lib/"

define DEFAULT_LIB_PATH "lib/"

but files are not loaded from 'assets/lib' maybe I missed something https://github.com/mangband/mangband/blob/develop/src/client/c-init.c#L188 SDL_AndroidGetInternalStoragePath(); VVVVV z-file.c.zip

keyboard control example it is possible to include java code 'src/main/java/org' https://github.com/Cuboideb/angbandroid https://github.com/Cuboideb/angbandroid/tree/master/app/src/main/java/org/rephial/xyangband 42457567456