mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-12-09 08:02:40 +00:00
ci: build simple Android SDL app using gradle
This commit is contained in:
committed by
Anonymous Maarten
parent
8954e42bcb
commit
e10666397e
@@ -24,7 +24,7 @@ android {
|
||||
abiFilters 'arm64-v8a'
|
||||
}
|
||||
cmake {
|
||||
arguments "-DANDROID_APP_PLATFORM=android-19", "-DANDROID_STL=c++_static"
|
||||
arguments "-DANDROID_PLATFORM=android-19", "-DANDROID_STL=c++_static"
|
||||
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
|
||||
abiFilters 'arm64-v8a'
|
||||
}
|
||||
@@ -45,12 +45,12 @@ android {
|
||||
jniLibs.srcDir 'libs'
|
||||
}
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
path 'jni/Android.mk'
|
||||
}
|
||||
// cmake {
|
||||
// path 'jni/CMakeLists.txt'
|
||||
// ndkBuild {
|
||||
// path 'jni/Android.mk'
|
||||
// }
|
||||
cmake {
|
||||
path 'jni/CMakeLists.txt'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,29 @@
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
|
||||
project(MY_APP)
|
||||
project(my_app)
|
||||
|
||||
find_library(SDL3 SDL3)
|
||||
if(NOT TARGET SDL3::SDL3)
|
||||
find_package(SDL3 CONFIG)
|
||||
endif()
|
||||
|
||||
add_library(main SHARED)
|
||||
if(NOT TARGET SDL3::SDL3)
|
||||
find_library(SDL3_LIBRARY NAMES "SDL3")
|
||||
find_path(SDL3_INCLUDE_DIR NAMES "SDL3/SDL.h")
|
||||
add_library(SDL3::SDL3 UNKNOWN IMPORTED)
|
||||
set_property(TARGET SDL3::SDL3 PROPERTY IMPORTED_LOCATION "${SDL3_LIBRARY}")
|
||||
set_property(TARGET SDL3::SDL3 PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIR}")
|
||||
endif()
|
||||
|
||||
target_sources(main PRIVATE YourSourceHere.c)
|
||||
|
||||
target_link_libraries(main SDL3)
|
||||
if(NOT TARGET SDL3::SDL3)
|
||||
message(FATAL_ERROR "Cannot find SDL3.
|
||||
|
||||
Possible ways to fix this:
|
||||
- Use a SDL3 Android aar archive, and configure gradle to use it: prefab is required.
|
||||
- Add add_subdirectory(path/to/SDL) to your CMake script, and make sure a vendored SDL is present there.
|
||||
")
|
||||
endif()
|
||||
|
||||
add_library(main SHARED
|
||||
YourSourceHere.c
|
||||
)
|
||||
target_link_libraries(main PRIVATE SDL3::SDL3)
|
||||
|
||||
26
android-project/app/jni/src/YourSourceHere.c
Normal file
26
android-project/app/jni/src/YourSourceHere.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
|
||||
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
|
||||
/* */
|
||||
/* Remove this source, and replace with your SDL sources */
|
||||
/* */
|
||||
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
if (SDL_Init(SDL_INIT_EVENTS | SDL_INIT_VIDEO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init failed (%s)", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Hello World",
|
||||
"!! Your SDL project successfully runs on Android !!", NULL) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_ShowSimpleMessageBox failed (%s)", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user