Skip to content

Commit

Permalink
Merge pull request #2475 from Ghabry/android-cmake
Browse files Browse the repository at this point in the history
Migrate Android build to gradle+CMake
  • Loading branch information
carstene1ns authored Mar 17, 2021
2 parents 5ceac13 + db65a48 commit 4a5a823
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 240 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ __MACOSX

# Android
*.iml
local.properties

# libretro
easyrpg_libretro.*
24 changes: 23 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,29 @@ 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
src/sdl2_ui.h)
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)
Expand Down Expand Up @@ -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()
Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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??
Expand Down
1 change: 1 addition & 0 deletions builds/android/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.cxx/
45 changes: 36 additions & 9 deletions builds/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,58 @@
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
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'
}
}
android {
sourceSets {
main {
jni.srcDirs = []
externalNativeBuild {
cmake {
path "../../../CMakeLists.txt"
version "3.10.2"
}
}
defaultConfig {
externalNativeBuild {
cmake {
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(" "))
}
}
}
}
lintOptions {
disable 'MissingTranslation'
abortOnError false
}
productFlavors {
}
}

allprojects {
Expand All @@ -37,8 +64,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'
}
15 changes: 15 additions & 0 deletions builds/android/app/src/gamebrowser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected String[] getLibraries() {
// "SDL2_mixer",
// "SDL2_net",
// "SDL2_ttf",
"main"
"easyrpg_android"
};
}

Expand Down
1 change: 0 additions & 1 deletion builds/android/app/src/main/jni/Android.mk

This file was deleted.

5 changes: 0 additions & 5 deletions builds/android/app/src/main/jni/Application.mk

This file was deleted.

15 changes: 0 additions & 15 deletions builds/android/app/src/main/jni/SDL2/Android.mk

This file was deleted.

141 changes: 0 additions & 141 deletions builds/android/app/src/main/jni/deps/Android.mk

This file was deleted.

Loading

0 comments on commit 4a5a823

Please sign in to comment.