isle-portable/android-project/app/build.gradle
Cookie f06731784e
Android port (#656)
* initial files

* get building

* proper paths & default to virtual mouse

* Wrap gradle under cmake & build SDL3.aar

run cmake with  -DANDROID_NDK_PATH=/path/to/ndk to generate the .aar & run the gradle build

if using Android Studio you will have to run the aar script manually(or do the cmake cmd) then put the normal cmake args inside '-PcmakeArgs="-DCMAKE_BUILD_TYPE=Release ...."'  at `Settings > Build, Execution, Deployment > Gradle-Android Compiler > Command-line Options`
Check CMakeLists.txt Android build block for more info

* workflow and format

* dont cmake -> gradle -> cmake

* icons

* prevent first start crash due to missing isle.ini

dont force require gles3 (vulkan & software are options)

* cleanup

* cmake script & ci cleanup

use a cmake script to downoad SDL3 sources for aar building

* script cleanups & gradle stub for android studio

handle the env var setting for the sdl3 aar build script

* signing

needed repository secrets:
- keystore  :  key.jks in base64
- keystorePassword  :  Key store password
- keyAlias  :  Key alias, ex key0
- keyPassword  :  Key Password

* conditionally run action without keys

* compile SDL once & cross-platformize gradle tasks

* suggestions

* use find_package over manual configuration

* use MxString

---------

Co-authored-by: Anders Jenbo <anders@jenbo.dk>
Co-authored-by: Christian Semmler <mail@csemmler.com>
2025-08-15 15:12:35 +00:00

102 lines
3.0 KiB
Groovy

plugins {
id 'com.android.application'
}
def androidProject = projectDir.parentFile
android {
namespace "org.legoisland.isle"
compileSdk 35
defaultConfig {
applicationId 'org.legoisland.isle'
minSdk 21
targetSdk 35
versionCode 1
versionName '1.0'
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared', "-DFETCHCONTENT_BASE_DIR=${androidProject}/build/_deps"
if (project.hasProperty('cmakeArgs')) {
project.cmakeArgs.split(" ").each {arg -> arguments arg}
}
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}
}
externalNativeBuild {
cmake {
version "3.30.5"
path '../../CMakeLists.txt'
}
}
signingConfigs {
register("release") {
enableV4Signing = true
keyAlias = System.getenv("SIGNING_KEY_ALIAS")
keyPassword = System.getenv("SIGNING_KEY_PASSWORD")
System.getenv("SIGNING_STORE_FILE")?.with { storeFile = file(it) }
storePassword = System.getenv("SIGNING_STORE_PASSWORD")
}
}
buildTypes {
release {
minifyEnabled true
signingConfig = signingConfigs.getByName("release")
// proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
prefab true
}
}
afterEvaluate {
def androidPath = System.getenv("ANDROID_HOME") ?: android.sdkDirectory
def ndkPath = System.getenv("ANDROID_NDK_HOME") ?: android.ndkDirectory
tasks.named('compileSDL3AndroidArchive').configure {
environment "ANDROID_HOME", androidPath
environment "ANDROID_NDK_HOME", ndkPath
}
}
def aarDest = project.providers.provider { file("${projectDir}/libs/SDL3.aar") }
tasks.register('downloadSDL3', Exec) {
workingDir = androidProject
commandLine 'cmake', '-P', 'downloadSDL3.cmake'
}
tasks.register('compileSDL3AndroidArchive', Exec) {
workingDir = androidProject
dependsOn(downloadSDL3)
def sdl3Dir = "build/_deps/sdl3-src"
commandLine 'python', "${sdl3Dir}/build-scripts/build-release.py",
'--actions', 'android',
'--fast', '--force',
"--root=${sdl3Dir}"
doLast {
def aarFile = file("${androidProject}/${sdl3Dir}/build-android").listFiles().find {
it.name.endsWith(".aar")
}
aarDest.get().parentFile.mkdirs()
aarFile.renameTo(aarDest.get())
}
}
tasks.register('ensureSDL3') {
// if DOWNLOAD_DEPENDENCIES=OFF download the version appropriate
// 'devel android zip' and place the .aar at `aarDest`
if (aarDest.get().exists()) { return false }
dependsOn(compileSDL3AndroidArchive)
}
dependencies {
implementation files('libs/SDL3.aar').builtBy(ensureSDL3)
}