From ab6ee910b1aa0884c95b2a2f01eb896fb1be1b6f Mon Sep 17 00:00:00 2001 From: Ghabry Date: Thu, 11 Mar 2021 18:25:42 +0100 Subject: [PATCH 1/4] Migrate Android build to gradle+CMake To build set EASYRPG_TOOLCHAIN_DIR and EASYRPG_LIBLCF_DIR to the paths that contain all the Android toolchains. Then run "gradle assembleRelease" and the magic happens. Fix #621 --- .gitignore | 1 + CMakeLists.txt | 24 ++- builds/android/app/.gitignore | 1 + builds/android/app/build.gradle | 26 ++-- .../app/src/gamebrowser/CMakeLists.txt | 15 ++ ...asyrpg_player_game_browser_GameScanner.cpp | 0 ..._easyrpg_player_game_browser_GameScanner.h | 0 .../main/java/org/libsdl/app/SDLActivity.java | 2 +- builds/android/app/src/main/jni/Android.mk | 1 - .../android/app/src/main/jni/Application.mk | 5 - .../android/app/src/main/jni/SDL2/Android.mk | 15 -- .../android/app/src/main/jni/deps/Android.mk | 141 ------------------ .../app/src/main/jni/gamebrowser/Android.mk | 22 --- .../android/app/src/main/jni/src/Android.mk | 41 ----- builds/android/build.gradle | 2 +- builds/android/gradle.properties | 1 - builds/cmake/Modules/FindSDL2.cmake | 8 +- ...pg_player_player_EasyRpgPlayerActivity.cpp | 0 ...yrpg_player_player_EasyRpgPlayerActivity.h | 0 19 files changed, 65 insertions(+), 240 deletions(-) create mode 100644 builds/android/app/.gitignore create mode 100644 builds/android/app/src/gamebrowser/CMakeLists.txt rename builds/android/app/src/{main/jni => }/gamebrowser/org_easyrpg_player_game_browser_GameScanner.cpp (100%) rename builds/android/app/src/{main/jni => }/gamebrowser/org_easyrpg_player_game_browser_GameScanner.h (100%) delete mode 100644 builds/android/app/src/main/jni/Android.mk delete mode 100644 builds/android/app/src/main/jni/Application.mk delete mode 100644 builds/android/app/src/main/jni/SDL2/Android.mk delete mode 100644 builds/android/app/src/main/jni/deps/Android.mk delete mode 100644 builds/android/app/src/main/jni/gamebrowser/Android.mk delete mode 100644 builds/android/app/src/main/jni/src/Android.mk rename {builds/android/app/src/main/jni/src => src/platform/android}/org_easyrpg_player_player_EasyRpgPlayerActivity.cpp (100%) rename {builds/android/app/src/main/jni/src => src/platform/android}/org_easyrpg_player_player_EasyRpgPlayerActivity.h (100%) diff --git a/.gitignore b/.gitignore index 5b4bcc76a0..a4216cb2a1 100644 --- a/.gitignore +++ b/.gitignore @@ -106,6 +106,7 @@ __MACOSX # Android *.iml +local.properties # libretro easyrpg_libretro.* diff --git a/CMakeLists.txt b/CMakeLists.txt index e849f4a09c..7e98769e9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -442,6 +442,15 @@ set_property(CACHE PLAYER_TARGET_PLATFORM PROPERTY STRINGS SDL2 libretro) set(PLAYER_BUILD_EXECUTABLE ON) set(PLAYER_TEST_LIBRARIES ${PROJECT_NAME}) +if(ANDROID AND PLAYER_GRADLE_BUILD) + # Build invoked by Gradle + # Ugly: Gradle has no way to branch based on the ABI + # Inject correct search path based on PLAYER_ANDROID_TOOLCHAIN_PATH + foreach(f ${PLAYER_ANDROID_TOOLCHAIN_PATH}) + list(APPEND CMAKE_FIND_ROOT_PATH "${f}/${ANDROID_ABI}-toolchain") + endforeach(f) +endif() + if(${PLAYER_TARGET_PLATFORM} STREQUAL "SDL2") target_sources(${PROJECT_NAME} PRIVATE src/sdl2_ui.cpp @@ -449,7 +458,13 @@ if(${PLAYER_TARGET_PLATFORM} STREQUAL "SDL2") target_compile_definitions(${PROJECT_NAME} PUBLIC USE_SDL=2) find_package(SDL2 2.0.5 REQUIRED) - target_link_libraries(${PROJECT_NAME} SDL2::SDL2main) + if(ANDROID) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/builds/android/app/src/gamebrowser) + target_link_libraries(${PROJECT_NAME} SDL2::SDL2) + set(PLAYER_BUILD_EXECUTABLE OFF) + else() + target_link_libraries(${PROJECT_NAME} SDL2::SDL2main) + endif() elseif(${PLAYER_TARGET_PLATFORM} STREQUAL "libretro") target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LIBRETRO=1) set(PLAYER_BUILD_EXECUTABLE OFF) @@ -872,6 +887,13 @@ else() target_link_libraries(easyrpg_libretro ${PROJECT_NAME}) set_target_properties(easyrpg_libretro PROPERTIES PREFIX "") set(PLAYER_TEST_LIBRARIES "easyrpg_libretro") + elseif(ANDROID AND ${PLAYER_TARGET_PLATFORM} STREQUAL "SDL2") + add_library(easyrpg_android + src/platform/android/org_easyrpg_player_player_EasyRpgPlayerActivity.cpp + src/platform/android/org_easyrpg_player_player_EasyRpgPlayerActivity.h + src/main.cpp) + target_link_libraries(easyrpg_android ${PROJECT_NAME}) + set(PLAYER_TEST_LIBRARIES "easyrpg_android") else() message(FATAL_ERROR "Unsupported library target platform ${PLAYER_TARGET_PLATFORM}") endif() diff --git a/builds/android/app/.gitignore b/builds/android/app/.gitignore new file mode 100644 index 0000000000..3166b90b04 --- /dev/null +++ b/builds/android/app/.gitignore @@ -0,0 +1 @@ +.cxx/ diff --git a/builds/android/app/build.gradle b/builds/android/app/build.gradle index d7cad5313a..639881d199 100644 --- a/builds/android/app/build.gradle +++ b/builds/android/app/build.gradle @@ -1,7 +1,8 @@ apply plugin: 'com.android.application' android { compileSdkVersion 29 - buildToolsVersion '29.0.2' + buildToolsVersion '29.0.3' + ndkVersion '21.4.7075529' defaultConfig { applicationId "org.easyrpg.player" minSdkVersion 14 @@ -13,10 +14,19 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } - android { - sourceSets { - main { - jni.srcDirs = [] + externalNativeBuild { + cmake { + path "../../../CMakeLists.txt" + version "3.10.2" + } + } + defaultConfig { + externalNativeBuild { + cmake { + arguments "-DPLAYER_ANDROID_TOOLCHAIN_PATH=${System.env.EASYRPG_TOOLCHAIN_DIR};${System.env.EASYRPG_LIBLCF_DIR}", + "-DPLAYER_GRADLE_BUILD=ON", + "-DBUILD_SHARED_LIBS=ON", + "-DPLAYER_ENABLE_TESTS=OFF" } } } @@ -24,8 +34,6 @@ android { disable 'MissingTranslation' abortOnError false } - productFlavors { - } } allprojects { @@ -37,8 +45,8 @@ allprojects { } dependencies { - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'com.google.android.material:material:1.1.0' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.1.0' } diff --git a/builds/android/app/src/gamebrowser/CMakeLists.txt b/builds/android/app/src/gamebrowser/CMakeLists.txt new file mode 100644 index 0000000000..d578ec7b92 --- /dev/null +++ b/builds/android/app/src/gamebrowser/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.7) + +project(easyrpg_android VERSION 1.0 LANGUAGES CXX) + +add_library(gamebrowser + org_easyrpg_player_game_browser_GameScanner.cpp + org_easyrpg_player_game_browser_GameScanner.h +) + +find_package(PNG REQUIRED) +target_link_libraries(gamebrowser PNG::PNG) + +if(BUILD_SHARED_LIBS) + set_property(TARGET gamebrowser PROPERTY POSITION_INDEPENDENT_CODE ON) +endif() diff --git a/builds/android/app/src/main/jni/gamebrowser/org_easyrpg_player_game_browser_GameScanner.cpp b/builds/android/app/src/gamebrowser/org_easyrpg_player_game_browser_GameScanner.cpp similarity index 100% rename from builds/android/app/src/main/jni/gamebrowser/org_easyrpg_player_game_browser_GameScanner.cpp rename to builds/android/app/src/gamebrowser/org_easyrpg_player_game_browser_GameScanner.cpp diff --git a/builds/android/app/src/main/jni/gamebrowser/org_easyrpg_player_game_browser_GameScanner.h b/builds/android/app/src/gamebrowser/org_easyrpg_player_game_browser_GameScanner.h similarity index 100% rename from builds/android/app/src/main/jni/gamebrowser/org_easyrpg_player_game_browser_GameScanner.h rename to builds/android/app/src/gamebrowser/org_easyrpg_player_game_browser_GameScanner.h diff --git a/builds/android/app/src/main/java/org/libsdl/app/SDLActivity.java b/builds/android/app/src/main/java/org/libsdl/app/SDLActivity.java index 4e8cde71b9..1b0ac15bbc 100644 --- a/builds/android/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/builds/android/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -172,7 +172,7 @@ protected String[] getLibraries() { // "SDL2_mixer", // "SDL2_net", // "SDL2_ttf", - "main" + "easyrpg_android" }; } diff --git a/builds/android/app/src/main/jni/Android.mk b/builds/android/app/src/main/jni/Android.mk deleted file mode 100644 index 5053e7d643..0000000000 --- a/builds/android/app/src/main/jni/Android.mk +++ /dev/null @@ -1 +0,0 @@ -include $(call all-subdir-makefiles) diff --git a/builds/android/app/src/main/jni/Application.mk b/builds/android/app/src/main/jni/Application.mk deleted file mode 100644 index df2ad011e4..0000000000 --- a/builds/android/app/src/main/jni/Application.mk +++ /dev/null @@ -1,5 +0,0 @@ -# Uncomment this if you're using STL in your project -# See CPLUSPLUS-SUPPORT.html in the NDK documentation for more information - -APP_STL := c++_static -APP_ABI := armeabi-v7a arm64-v8a x86 x86_64 diff --git a/builds/android/app/src/main/jni/SDL2/Android.mk b/builds/android/app/src/main/jni/SDL2/Android.mk deleted file mode 100644 index e43493ecb3..0000000000 --- a/builds/android/app/src/main/jni/SDL2/Android.mk +++ /dev/null @@ -1,15 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -EASYRPG_TOOLCHAIN_DIR = $(EASYDEV_ANDROID)/$(TARGET_ARCH_ABI)-toolchain - -# SDL2 -include $(CLEAR_VARS) -LOCAL_MODULE := SDL2 -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/lib$(LOCAL_MODULE).so -include $(PREBUILT_SHARED_LIBRARY) - -# hidapi (since SDL 2.0.9) -include $(CLEAR_VARS) -LOCAL_MODULE := hidapi -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libhidapi.so -include $(PREBUILT_SHARED_LIBRARY) diff --git a/builds/android/app/src/main/jni/deps/Android.mk b/builds/android/app/src/main/jni/deps/Android.mk deleted file mode 100644 index 0491d25204..0000000000 --- a/builds/android/app/src/main/jni/deps/Android.mk +++ /dev/null @@ -1,141 +0,0 @@ -EASYRPG_TOOLCHAIN_DIR = $(EASYDEV_ANDROID)/$(TARGET_ARCH_ABI)-toolchain - -# png -include $(CLEAR_VARS) -LOCAL_MODULE := png -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include/libpng16 -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libpng.a -include $(PREBUILT_STATIC_LIBRARY) - -# pixman -include $(CLEAR_VARS) -LOCAL_MODULE := pixman-1 -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include/pixman-1 -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libpixman-1.a -include $(PREBUILT_STATIC_LIBRARY) - -# freetype2 -include $(CLEAR_VARS) -LOCAL_MODULE := freetype -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include/freetype2 -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libfreetype.a -include $(PREBUILT_STATIC_LIBRARY) - -# xmp-lite -include $(CLEAR_VARS) -LOCAL_MODULE := xmp-lite -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include/libxmp-lite -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libxmp-lite.a -include $(PREBUILT_STATIC_LIBRARY) - -# sndfile -include $(CLEAR_VARS) -LOCAL_MODULE := sndfile -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libsndfile.a -include $(PREBUILT_STATIC_LIBRARY) - -# speexdsp -include $(CLEAR_VARS) -LOCAL_MODULE := speexdsp -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libspeexdsp.a -include $(PREBUILT_STATIC_LIBRARY) - -# mpg123 -include $(CLEAR_VARS) -LOCAL_MODULE := mpg123 -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libmpg123.a -include $(PREBUILT_STATIC_LIBRARY) - -# ogg -include $(CLEAR_VARS) -LOCAL_MODULE := ogg -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libogg.a -include $(PREBUILT_STATIC_LIBRARY) - -# vorbis -include $(CLEAR_VARS) -LOCAL_MODULE := vorbis -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libvorbis.a -include $(PREBUILT_STATIC_LIBRARY) - -# vorbisfile -include $(CLEAR_VARS) -LOCAL_MODULE := vorbisfile -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libvorbisfile.a -include $(PREBUILT_STATIC_LIBRARY) - -# expat -include $(CLEAR_VARS) -LOCAL_MODULE := expat -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libexpat.a -include $(PREBUILT_STATIC_LIBRARY) - -# opus -include $(CLEAR_VARS) -LOCAL_MODULE := opus -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libopus.a -include $(PREBUILT_STATIC_LIBRARY) - -# opusfile -include $(CLEAR_VARS) -LOCAL_MODULE := opusfile -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include/opus -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libopusfile.a -include $(PREBUILT_STATIC_LIBRARY) - -# fmt -include $(CLEAR_VARS) -LOCAL_MODULE := fmt -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libfmt.a -include $(PREBUILT_STATIC_LIBRARY) - -# WildMidi -include $(CLEAR_VARS) -LOCAL_MODULE := WildMidi -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libWildMidi.a -include $(PREBUILT_STATIC_LIBRARY) - -# FluidLite -include $(CLEAR_VARS) -LOCAL_MODULE := fluidlite -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libfluidlite.a -include $(PREBUILT_STATIC_LIBRARY) - -# icui18n -include $(CLEAR_VARS) -LOCAL_MODULE := icui18n -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libicui18n.a -include $(PREBUILT_STATIC_LIBRARY) - -# icuuc -include $(CLEAR_VARS) -LOCAL_MODULE := icuuc -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libicuuc.a -include $(PREBUILT_STATIC_LIBRARY) - -# icudata -include $(CLEAR_VARS) -LOCAL_MODULE := icudata -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/libicudata.a -include $(PREBUILT_STATIC_LIBRARY) - -# lcf -include $(CLEAR_VARS) -LOCAL_MODULE := lcf -LOCAL_EXPORT_C_INCLUDES := $(EASYRPG_TOOLCHAIN_DIR)/include -LOCAL_SRC_FILES := $(EASYRPG_TOOLCHAIN_DIR)/lib/liblcf.a -include $(PREBUILT_STATIC_LIBRARY) diff --git a/builds/android/app/src/main/jni/gamebrowser/Android.mk b/builds/android/app/src/main/jni/gamebrowser/Android.mk deleted file mode 100644 index 3e991e37de..0000000000 --- a/builds/android/app/src/main/jni/gamebrowser/Android.mk +++ /dev/null @@ -1,22 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -EASYRPG_TOOLCHAIN_DIR = $(EASYDEV_ANDROID)/$(TARGET_ARCH_ABI)-toolchain - -include $(CLEAR_VARS) - -LOCAL_MODULE := gamebrowser - -LOCAL_C_INCLUDES := - -LOCAL_SRC_FILES := \ - org_easyrpg_player_game_browser_GameScanner.cpp - -LOCAL_LDLIBS := -llog -lz -latomic - -LOCAL_STATIC_LIBRARIES := png - -LOCAL_CFLAGS := -O2 -Wall -Wextra -fno-math-errno - -LOCAL_CXXFLAGS := $(LOCAL_C_FLAGS) -std=c++14 -fno-rtti - -include $(BUILD_SHARED_LIBRARY) diff --git a/builds/android/app/src/main/jni/src/Android.mk b/builds/android/app/src/main/jni/src/Android.mk deleted file mode 100644 index 32a5f18381..0000000000 --- a/builds/android/app/src/main/jni/src/Android.mk +++ /dev/null @@ -1,41 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -EASYRPG_TOOLCHAIN_DIR = $(EASYDEV_ANDROID)/$(TARGET_ARCH_ABI)-toolchain - -include $(CLEAR_VARS) - -LOCAL_MODULE := main - -PLAYER_PATH := ../../../../../../../ - -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH)/$(PLAYER_PATH)/src \ - $(EASYRPG_TOOLCHAIN_DIR)/include/SDL2 - -# Add your application source files here... -LOCAL_SRC_FILES := \ - org_easyrpg_player_player_EasyRpgPlayerActivity.cpp \ - $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/$(PLAYER_PATH)/src/*.cpp)) - -LOCAL_SHARED_LIBRARIES := SDL2 hidapi - -LOCAL_STATIC_LIBRARIES := \ - vorbisfile vorbis ogg WildMidi \ - xmp-lite mpg123 speexdsp sndfile \ - freetype pixman-1 png opusfile opus \ - fluidlite \ - lcf expat icui18n icuuc icudata \ - cpufeatures fmt - -LOCAL_LDLIBS := -lGLESv1_CM -llog -lz -latomic - -LOCAL_CFLAGS := -O2 -Wall -Wextra -DUSE_SDL=2 -fno-math-errno \ - -DHAVE_MPG123 -DWANT_FMMIDI -DHAVE_OPUS -DHAVE_WILDMIDI \ - -DHAVE_OGGVORBIS -DHAVE_XMP -DHAVE_LIBSNDFILE \ - -DHAVE_LIBSPEEXDSP -DHAVE_FLUIDLITE -DSUPPORT_AUDIO - -LOCAL_CXXFLAGS := $(LOCAL_C_FLAGS) -std=c++14 -fno-rtti - -include $(BUILD_SHARED_LIBRARY) - -$(call import-module,android/cpufeatures) diff --git a/builds/android/build.gradle b/builds/android/build.gradle index da2f7cd34f..dc504d0209 100644 --- a/builds/android/build.gradle +++ b/builds/android/build.gradle @@ -5,7 +5,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + classpath 'com.android.tools.build:gradle:4.0.2' } } diff --git a/builds/android/gradle.properties b/builds/android/gradle.properties index 16498a1101..dbb7bf70d1 100644 --- a/builds/android/gradle.properties +++ b/builds/android/gradle.properties @@ -1,3 +1,2 @@ android.enableJetifier=true android.useAndroidX=true -android.useDeprecatedNdk=true diff --git a/builds/cmake/Modules/FindSDL2.cmake b/builds/cmake/Modules/FindSDL2.cmake index 945463f483..6dc456e449 100644 --- a/builds/cmake/Modules/FindSDL2.cmake +++ b/builds/cmake/Modules/FindSDL2.cmake @@ -54,7 +54,7 @@ endif() find_package(PkgConfig QUIET) set(SDL2_INCLUDE_HINTS) set(SDL2_LIB_HINTS) -if(PKG_CONFIG_FOUND) +if(PKG_CONFIG_FOUND AND NOT ANDROID) pkg_search_module(SDL2PC QUIET sdl2) if(SDL2PC_INCLUDE_DIRS) set(SDL2_INCLUDE_HINTS ${SDL2PC_INCLUDE_DIRS}) @@ -125,7 +125,7 @@ if(WIN32 AND SDL2_LIBRARY) endif() -if(WIN32 OR ANDROID OR IOS OR (APPLE AND NOT _sdl2_framework)) +if(WIN32 OR IOS OR (APPLE AND NOT _sdl2_framework)) set(SDL2_EXTRA_REQUIRED SDL2_SDLMAIN_LIBRARY) find_library(SDL2_SDLMAIN_LIBRARY NAMES @@ -256,6 +256,10 @@ if(SDL2_FOUND) ${IOKIT} ${FORCEFEEDBACK} ${CARBON_LIBRARY} ${COREAUDIO} ${AUDIOTOOLBOX} ${AUDIOUNIT} ${METAL} ${ICONV_LIBRARY}) + elseif(ANDROID) + find_library(HIDAPI hidapi) + set_property(TARGET SDL2::SDL2 APPEND_STRING PROPERTY + INTERFACE_LINK_LIBRARIES ${HIDAPI}) else() # Remove -lSDL2 -lSDL2main from the pkg-config linker line, # to prevent linking against the system library diff --git a/builds/android/app/src/main/jni/src/org_easyrpg_player_player_EasyRpgPlayerActivity.cpp b/src/platform/android/org_easyrpg_player_player_EasyRpgPlayerActivity.cpp similarity index 100% rename from builds/android/app/src/main/jni/src/org_easyrpg_player_player_EasyRpgPlayerActivity.cpp rename to src/platform/android/org_easyrpg_player_player_EasyRpgPlayerActivity.cpp diff --git a/builds/android/app/src/main/jni/src/org_easyrpg_player_player_EasyRpgPlayerActivity.h b/src/platform/android/org_easyrpg_player_player_EasyRpgPlayerActivity.h similarity index 100% rename from builds/android/app/src/main/jni/src/org_easyrpg_player_player_EasyRpgPlayerActivity.h rename to src/platform/android/org_easyrpg_player_player_EasyRpgPlayerActivity.h From c4906571988102789696b43299eff9959cd1a220 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Thu, 11 Mar 2021 20:01:12 +0100 Subject: [PATCH 2/4] Android: The toolchain dirs are now passed via -PtoolchainDirs="PATH_ONE;PATH_TWO;PATH_THREE" instead of an env var Additional CMake arguments are possible with -PcmakeOptions or env var ORG_GRADLE_PROJECT_cmakeOptions --- builds/android/app/build.gradle | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/builds/android/app/build.gradle b/builds/android/app/build.gradle index 639881d199..c232b9a4b1 100644 --- a/builds/android/app/build.gradle +++ b/builds/android/app/build.gradle @@ -23,10 +23,17 @@ android { defaultConfig { externalNativeBuild { cmake { - arguments "-DPLAYER_ANDROID_TOOLCHAIN_PATH=${System.env.EASYRPG_TOOLCHAIN_DIR};${System.env.EASYRPG_LIBLCF_DIR}", - "-DPLAYER_GRADLE_BUILD=ON", + arguments "-DPLAYER_GRADLE_BUILD=ON", "-DBUILD_SHARED_LIBS=ON", "-DPLAYER_ENABLE_TESTS=OFF" + + if (project.hasProperty("toolchainDirs")) { + arguments.add('-DPLAYER_ANDROID_TOOLCHAIN_PATH=' + project.properties['toolchainDirs']) + } + + if (project.hasProperty("cmakeOptions")) { + arguments.addAll(project.properties['cmakeOptions'].split(" ")) + } } } } From b38e3ee1e9ee2abafaa9cdafe079be1859ea13a8 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Wed, 17 Mar 2021 16:29:40 +0100 Subject: [PATCH 3/4] Add Android build instructions to Readme --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index adc3c27d40..d2fed58d8c 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,15 @@ https://easyrpg.org/downloads/player/ ## Building +### Dependencies: + +If your operating system has a package manager, we recommend installing the +dependencies with it. + +In case you want to compile the dependencies yourself, you can find them, +except for [liblcf], in our [buildscripts] repository. + + ### Autotools Makefile method: Building requirements: @@ -113,6 +122,7 @@ https://wiki.easyrpg.org/development/compiling/player/cmake CMake is the only supported way to build Player for Windows. All dependencies must be installed with [vcpkg]. + ### Building a libretro core: Building for libretro is based on the CMake method. @@ -130,6 +140,30 @@ Set shared libs to ON or OFF depending on which type of libraries RetroArch uses on the platform you are targeting. +### Building an Android APK: + +Building requirements: + +- Android SDK with NDK r21 + +Step-by-step instructions: + + tar xf easyrpg-player-0.6.2.tar.xz # unpack the tarball + cd easyrpg-player-0.6.2/builds/android # enter in the android directory + ./gradlew -PtoolchainDirs="DIR1;DIR2" assembleRelease # create the APK + +Replace ``DIR1`` etc. with the path to the player dependencies. You can use +the scripts in the ``android`` folder of our [buildscripts] to compile them. + +To pass additional CMake arguments use ``-PcmakeOptions``: + + -PcmakeOptions="-DSOME_OPTION1=ON -DSOME_OPTION2=OFF" + +The unsigned APK is stored in: + + app/build/outputs/apk/release/app-release-unsigned.apk + + ## Running EasyRPG Player Run the `easyrpg-player` executable from a RPG Maker 2000 or 2003 game @@ -166,6 +200,7 @@ EasyRPG Player makes use of the following 3rd party software: * [Teenyicons] - Copyright (c) 2020 Anja van Staden, provided under the MIT license +[buildscripts]: https://github.com/EasyRPG/buildscripts [liblcf]: https://github.com/EasyRPG/liblcf [vcpkg]: https://github.com/Microsoft/vcpkg [#easyrpg at irc.freenode.net]: https://kiwiirc.com/nextclient/#ircs://irc.freenode.net/#easyrpg?nick=rpgguest?? From db65a481eed7f22c80bd853ccab19db3c2ff3bc2 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Wed, 17 Mar 2021 18:30:54 +0100 Subject: [PATCH 4/4] Gradle: Provide VERSION_NAME/CODE and ABI_FILTERS_DEBUG/RELEASE via gradle.properties file --- builds/android/app/build.gradle | 12 ++++++++++++ builds/android/gradle.properties | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/builds/android/app/build.gradle b/builds/android/app/build.gradle index c232b9a4b1..2f0ded673a 100644 --- a/builds/android/app/build.gradle +++ b/builds/android/app/build.gradle @@ -7,9 +7,21 @@ android { applicationId "org.easyrpg.player" minSdkVersion 14 targetSdkVersion 29 + versionName VERSION_NAME + versionCode Integer.parseInt(VERSION_CODE) } buildTypes { + debug { + ndk { + abiFilters = [] + abiFilters.addAll(ABI_FILTERS_DEBUG.split(',')) + } + } release { + ndk { + abiFilters = [] + abiFilters.addAll(ABI_FILTERS_RELEASE.split(',')) + } minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } diff --git a/builds/android/gradle.properties b/builds/android/gradle.properties index dbb7bf70d1..162f676bfa 100644 --- a/builds/android/gradle.properties +++ b/builds/android/gradle.properties @@ -1,2 +1,8 @@ android.enableJetifier=true android.useAndroidX=true + +VERSION_NAME=1.0 +VERSION_CODE=1 + +ABI_FILTERS_DEBUG=armeabi-v7a +ABI_FILTERS_RELEASE=armeabi-v7a,arm64-v8a,x86,x86_64