Files
kichikuou 981c302dfc Migrate Android from SDL2 to SDL3
Make SDL3 the default and only supported SDL version for Android. Download
the official SDL3 Android AAR during Gradle configuration and expose it to
the native CMake build through Prefab. SDL_ttf 3 is built from source with
HarfBuzz and PlutoSVG disabled.
2026-09-16 09:24:40 +09:00

129 lines
4.0 KiB
Groovy

def buildAsLibrary = project.hasProperty('BUILD_AS_LIBRARY')
def buildAsApplication = !buildAsLibrary
if (buildAsApplication) {
apply plugin: 'com.android.application'
}
else {
apply plugin: 'com.android.library'
}
apply plugin: 'kotlin-android'
// Use SDL3's official prebuilt Android Archive (AAR). The AAR provides SDL3
// to the native CMake build through Prefab. If it is not available locally,
// download the official Android package and extract the AAR and license.
def sdlAarUrl = 'https://github.com/libsdl-org/SDL/releases/download/release-3.4.16/SDL3-devel-3.4.16-android.zip'
def sdlAarName = 'SDL3-3.4.16.aar'
def aarsDir = file('aars')
def assetsLicensesDir = file('src/main/assets/licenses')
aarsDir.mkdirs()
assetsLicensesDir.mkdirs()
def aarFile = new File(aarsDir, sdlAarName)
def licenseFile = new File(assetsLicensesDir, 'SDL')
if (!aarFile.exists() || !licenseFile.exists()) {
logger.lifecycle("Downloading ${sdlAarName} ...")
def tmpZip = File.createTempFile('sdl-aar', '.zip')
new URL(sdlAarUrl).withInputStream { input ->
tmpZip.withOutputStream { it << input }
}
copy {
from zipTree(tmpZip)
include sdlAarName
into aarsDir
}
copy {
from zipTree(tmpZip)
include 'LICENSE.txt'
into assetsLicensesDir
rename 'LICENSE.txt', 'SDL'
}
tmpZip.delete()
}
android {
if (buildAsApplication) {
namespace "io.github.kichikuou.system3"
}
buildFeatures {
prefab true
}
compileSdkVersion 34
defaultConfig {
minSdkVersion 21
targetSdkVersion 34
versionCode 17
versionName "1.8.0" + gitRevision()
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_static", "-DSYSTEM3_SDL_VERSION=3"
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
}
signingConfigs {
release {
storeFile rootProject.file('keystore.jks')
storePassword System.getenv('KEYSTORE_PASSWORD')
keyAlias System.getenv('KEY_ALIAS')
keyPassword System.getenv('KEY_PASSWORD')
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (rootProject.file('keystore.jks').exists()) {
signingConfig signingConfigs.release
}
}
}
applicationVariants.all { variant ->
tasks["merge${variant.name.capitalize()}Assets"]
.dependsOn("externalNativeBuild${variant.name.capitalize()}")
}
if (!project.hasProperty('EXCLUDE_NATIVE_LIBS')) {
sourceSets.main {
jniLibs.srcDir 'libs'
assets.srcDir '../../resources'
}
aaptOptions {
// Disable asset compression for fonts.
// Without this, text rendering will be very slow.
noCompress 'ttf', 'otf'
}
externalNativeBuild {
cmake {
version '3.22.1'
path 'jni/CMakeLists.txt'
}
}
}
lint {
abortOnError false
}
if (buildAsLibrary) {
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith(".aar")) {
def fileName = "org.libsdl.app.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation files(aarFile)
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
}
static String gitRevision() {
' (git ' + "git rev-parse --short HEAD".execute().text.trim() + ')'
}