mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-06 19:38:14 +00:00
ci: build simple Android SDL app using gradle
This commit is contained in:

committed by
Anonymous Maarten

parent
8954e42bcb
commit
e10666397e
41
.github/workflows/android.yml
vendored
41
.github/workflows/android.yml
vendored
@@ -15,33 +15,46 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
platform:
|
platform:
|
||||||
- { name: "Android.mk" }
|
- { name: "Android.mk", ndk-build: 1 }
|
||||||
|
- { name: "Gradle", gradle: 1 }
|
||||||
- { name: "CMake", cmake: 1, android_abi: "arm64-v8a", android_platform: 23, arch: "aarch64", artifact: "SDL-android-arm64", apk-artifact: "SDL-android-apks-arm64" }
|
- { name: "CMake", cmake: 1, android_abi: "arm64-v8a", android_platform: 23, arch: "aarch64", artifact: "SDL-android-arm64", apk-artifact: "SDL-android-apks-arm64" }
|
||||||
- { name: "CMake (lean and mean)", cmake: 1, cppflags: "-DSDL_LEAN_AND_MEAN=1", android_abi: "arm64-v8a", android_platform: 23, arch: "aarch64", artifact: "SDL-lean-android-arm64", apk-artifact: "SDL-lean-android-apks-arm64" }
|
- { name: "CMake (lean and mean)", cmake: 1, cppflags: "-DSDL_LEAN_AND_MEAN=1", android_abi: "arm64-v8a", android_platform: 23, arch: "aarch64", artifact: "SDL-lean-android-arm64", apk-artifact: "SDL-lean-android-apks-arm64" }
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: nttld/setup-ndk@v1
|
- uses: nttld/setup-ndk@v1
|
||||||
|
if: ${{ matrix.platform.cmake || matrix.platform.ndk-build }}
|
||||||
id: setup_ndk
|
id: setup_ndk
|
||||||
with:
|
with:
|
||||||
local-cache: true
|
local-cache: true
|
||||||
ndk-version: r21e
|
ndk-version: r21e
|
||||||
- name: Build (Android.mk)
|
- name: Build (Android.mk)
|
||||||
if: ${{ contains(matrix.platform.name, 'Android.mk') }}
|
if: ${{ matrix.platform.ndk-build }}
|
||||||
run: |
|
run: |
|
||||||
./build-scripts/androidbuildlibs.sh
|
./build-scripts/androidbuildlibs.sh
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v4
|
||||||
if: ${{ contains(matrix.platform.name, 'CMake') }}
|
if: ${{ matrix.platform.cmake || matrix.platform.gradle }}
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '11'
|
java-version: '17'
|
||||||
|
- name: Build app (Gradle)
|
||||||
|
if: ${{ matrix.platform.gradle }}
|
||||||
|
run: |
|
||||||
|
ln -s ${{ github.workspace }} ${{ github.workspace }}/android-project/app/jni/SDL
|
||||||
|
cd android-project
|
||||||
|
./gradlew -i assembleRelease
|
||||||
|
# - name: Build library (Gradle)
|
||||||
|
# if: ${{ matrix.platform.gradle }}
|
||||||
|
# run: |
|
||||||
|
# cd android-project
|
||||||
|
# ./gradlew -i assembleRelease -PBUILD_AS_LIBRARY=1
|
||||||
- name: Setup (CMake)
|
- name: Setup (CMake)
|
||||||
if: ${{ contains(matrix.platform.name, 'CMake') }}
|
if: ${{ matrix.platform.cmake }}
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install ninja-build pkg-config
|
sudo apt-get install ninja-build pkg-config
|
||||||
- name: Configure (CMake)
|
- name: Configure (CMake)
|
||||||
if: ${{ contains(matrix.platform.name, 'CMake') }}
|
if: ${{ matrix.platform.cmake }}
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B build \
|
cmake -S . -B build \
|
||||||
-DCMAKE_C_FLAGS="${{ matrix.platform.cppflags }}" \
|
-DCMAKE_C_FLAGS="${{ matrix.platform.cppflags }}" \
|
||||||
@@ -63,25 +76,25 @@ jobs:
|
|||||||
-DCMAKE_BUILD_TYPE=Release \
|
-DCMAKE_BUILD_TYPE=Release \
|
||||||
-GNinja
|
-GNinja
|
||||||
- name: Build (CMake)
|
- name: Build (CMake)
|
||||||
if: ${{ contains(matrix.platform.name, 'CMake') }}
|
if: ${{ matrix.platform.cmake }}
|
||||||
run: |
|
run: |
|
||||||
cmake --build build --config Release --parallel --verbose
|
cmake --build build --config Release --parallel --verbose
|
||||||
- name: Build test apk's (CMake)
|
- name: Build test apk's (CMake)
|
||||||
if: ${{ contains(matrix.platform.name, 'CMake') }}
|
if: ${{ matrix.platform.cmake }}
|
||||||
run: |
|
run: |
|
||||||
cmake --build build --config Release --parallel --verbose --target testautomation-apk testaudiocapture-apk testcontroller-apk testmultiaudio-apk testsprite-apk
|
cmake --build build --config Release --parallel --verbose --target testautomation-apk testaudiocapture-apk testcontroller-apk testmultiaudio-apk testsprite-apk
|
||||||
- name: Install (CMake)
|
- name: Install (CMake)
|
||||||
if: ${{ contains(matrix.platform.name, 'CMake') }}
|
if: ${{ matrix.platform.cmake }}
|
||||||
run: |
|
run: |
|
||||||
cmake --install build --config Release
|
cmake --install build --config Release
|
||||||
echo "SDL3_DIR=$(pwd)/prefix" >> $GITHUB_ENV
|
echo "SDL3_DIR=$(pwd)/prefix" >> $GITHUB_ENV
|
||||||
( cd prefix; find ) | LC_ALL=C sort -u
|
( cd prefix; find ) | LC_ALL=C sort -u
|
||||||
- name: Package (CPack)
|
- name: Package (CPack)
|
||||||
if: ${{ contains(matrix.platform.name, 'CMake') }}
|
if: ${{ matrix.platform.cmake }}
|
||||||
run: |
|
run: |
|
||||||
cmake --build build/ --config Release --target package
|
cmake --build build/ --config Release --target package
|
||||||
- name: Verify CMake configuration files
|
- name: Verify CMake configuration files
|
||||||
if: ${{ contains(matrix.platform.name, 'CMake') }}
|
if: ${{ matrix.platform.cmake }}
|
||||||
run: |
|
run: |
|
||||||
cmake -S cmake/test -B cmake_config_build -G Ninja \
|
cmake -S cmake/test -B cmake_config_build -G Ninja \
|
||||||
-DCMAKE_TOOLCHAIN_FILE=${{ steps.setup_ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake \
|
-DCMAKE_TOOLCHAIN_FILE=${{ steps.setup_ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake \
|
||||||
@@ -91,19 +104,19 @@ jobs:
|
|||||||
-DCMAKE_PREFIX_PATH=${{ env.SDL3_DIR }}
|
-DCMAKE_PREFIX_PATH=${{ env.SDL3_DIR }}
|
||||||
cmake --build cmake_config_build --verbose
|
cmake --build cmake_config_build --verbose
|
||||||
- name: Verify sdl3.pc
|
- name: Verify sdl3.pc
|
||||||
if: ${{ contains(matrix.platform.name, 'CMake') }}
|
if: ${{ matrix.platform.cmake }}
|
||||||
run: |
|
run: |
|
||||||
export CC="${{ steps.setup_ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=${{ matrix.platform.arch }}-none-linux-androideabi${{ matrix.platform.android_platform }}"
|
export CC="${{ steps.setup_ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=${{ matrix.platform.arch }}-none-linux-androideabi${{ matrix.platform.android_platform }}"
|
||||||
export PKG_CONFIG_PATH=${{ env.SDL3_DIR }}/lib/pkgconfig
|
export PKG_CONFIG_PATH=${{ env.SDL3_DIR }}/lib/pkgconfig
|
||||||
cmake/test/test_pkgconfig.sh
|
cmake/test/test_pkgconfig.sh
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
if: ${{ contains(matrix.platform.name, 'CMake') }}
|
if: ${{ matrix.platform.cmake }}
|
||||||
with:
|
with:
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
name: ${{ matrix.platform.artifact }}
|
name: ${{ matrix.platform.artifact }}
|
||||||
path: build/dist/SDL3*
|
path: build/dist/SDL3*
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
if: ${{ contains(matrix.platform.name, 'CMake') }}
|
if: ${{ matrix.platform.cmake }}
|
||||||
with:
|
with:
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
name: ${{ matrix.platform.apk-artifact }}
|
name: ${{ matrix.platform.apk-artifact }}
|
||||||
|
@@ -24,7 +24,7 @@ android {
|
|||||||
abiFilters 'arm64-v8a'
|
abiFilters 'arm64-v8a'
|
||||||
}
|
}
|
||||||
cmake {
|
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 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
|
||||||
abiFilters 'arm64-v8a'
|
abiFilters 'arm64-v8a'
|
||||||
}
|
}
|
||||||
@@ -45,12 +45,12 @@ android {
|
|||||||
jniLibs.srcDir 'libs'
|
jniLibs.srcDir 'libs'
|
||||||
}
|
}
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
ndkBuild {
|
// ndkBuild {
|
||||||
path 'jni/Android.mk'
|
// path 'jni/Android.mk'
|
||||||
}
|
|
||||||
// cmake {
|
|
||||||
// path 'jni/CMakeLists.txt'
|
|
||||||
// }
|
// }
|
||||||
|
cmake {
|
||||||
|
path 'jni/CMakeLists.txt'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,29 @@
|
|||||||
cmake_minimum_required(VERSION 3.6)
|
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)
|
if(NOT TARGET SDL3::SDL3)
|
||||||
|
message(FATAL_ERROR "Cannot find SDL3.
|
||||||
target_link_libraries(main 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