From dce02ae80ef91474ecf9bac9be7aa65915efb976 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Fri, 9 Oct 2026 10:15:38 -0400 Subject: [PATCH] Build: -Pmobilegl.androidApi=29 builds a separate API 29 library and plugin; the default stays 26. --- CMakeLists.txt | 11 +++++++---- android-plugin/app/build.gradle.kts | 13 +++++++++++-- build.gradle | 9 ++++++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce2b913b..b2e5667b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,12 +118,15 @@ if (ANDROID) "(gradle builds get this from minSdk ${MOBILEGL_ANDROID_API_LEVEL}, so " "check that minSdk instead of adding an override).") elseif (_mobilegl_android_api GREATER MOBILEGL_ANDROID_API_LEVEL) + # A higher level is a separate artifact of the SAME source (gradle -Pmobilegl.androidApi=29: + # native ELF TLS instead of emulated TLS). Any post-${MOBILEGL_ANDROID_API_LEVEL} API use must + # sit behind a compile-time __ANDROID_API__ gate and never replace the API + # ${MOBILEGL_ANDROID_API_LEVEL} path; the minSdk-${MOBILEGL_ANDROID_API_LEVEL} build stays the + # enforcing compile. message(STATUS "MobileGL: configuring at Android API ${_mobilegl_android_api} " - "(> shipping minimum ${MOBILEGL_ANDROID_API_LEVEL}). Allowed, but the " - "tree must not use post-${MOBILEGL_ANDROID_API_LEVEL} APIs - the " - "minSdk-${MOBILEGL_ANDROID_API_LEVEL} gradle build is the enforcing " - "compile.") + "(> shipping minimum ${MOBILEGL_ANDROID_API_LEVEL}): a separate artifact; " + "post-${MOBILEGL_ANDROID_API_LEVEL} APIs only behind a compile-time __ANDROID_API__ gate.") endif() message(STATUS "MobileGL: Android API level ${_mobilegl_android_api}") diff --git a/android-plugin/app/build.gradle.kts b/android-plugin/app/build.gradle.kts index 64811c88..86c577a3 100644 --- a/android-plugin/app/build.gradle.kts +++ b/android-plugin/app/build.gradle.kts @@ -52,6 +52,12 @@ fun Project.mobileGlDisaggregatedEnabled(): Boolean { fun Project.mobileGlApplicationIdSuffix(): String = (findProperty("mobilegl.applicationIdSuffix") ?: "").toString().trim() +// The Android API level of the build (the library's build.gradle reads the same property). Above +// the shipped 26 the APK is a separate artifact: it gets an ".apiNN" id suffix and "-apiNN" version +// suffix unless an explicit application-id suffix is given, so both installs can coexist. +fun Project.mobileGlAndroidApi(): Int = + (findProperty("mobilegl.androidApi") ?: System.getenv("MOBILEGL_ANDROID_API") ?: "26").toString().trim().toInt() + fun Project.runGit(vararg arguments: String): String? = runCatching { ProcessBuilder("git", *arguments) .directory(rootDir) @@ -123,8 +129,11 @@ android { defaultConfig { applicationId = "top.mobilegl.plugin" - mobileGlApplicationIdSuffix().takeIf { it.isNotEmpty() }?.let { applicationIdSuffix = it } - minSdk = 26 + val androidApi = mobileGlAndroidApi() + val idSuffix = mobileGlApplicationIdSuffix().ifEmpty { if (androidApi > 26) ".api$androidApi" else "" } + idSuffix.takeIf { it.isNotEmpty() }?.let { applicationIdSuffix = it } + if (androidApi > 26) versionNameSuffix = "-api$androidApi" + minSdk = androidApi targetSdk = 34 versionCode = mobileGlVersionMajor * 1_000_000 + mobileGlVersionMinor * 10_000 + mobileGlMonthlyRevision versionName = "%d.%02d.%s".format(mobileGlVersionMajor, mobileGlVersionMinor, mobileGlGitShortHash) diff --git a/build.gradle b/build.gradle index a745672e..c91d5502 100644 --- a/build.gradle +++ b/build.gradle @@ -51,6 +51,13 @@ def mobileGlBuildDisaggregated = { def mobileGlEnableLto = { (rootProject.findProperty('mobilegl.enableLto') ?: System.getenv('MOBILEGL_ENABLE_LTO') ?: 'ON') as String } +// The Android API level the library is built for: minSdk, and with it the NDK's ANDROID_PLATFORM. +// 26 is the shipped build. 29 is a SEPARATE artifact (its own library, plugin APK and FCL-embedded +// copy, never selected at load time): at 29 the NDK uses native ELF TLS instead of emulated TLS. +// -Pmobilegl.androidApi=29 (or MOBILEGL_ANDROID_API=29) selects it; the source is the same. +def mobileGlAndroidApi = { + (rootProject.findProperty('mobilegl.androidApi') ?: System.getenv('MOBILEGL_ANDROID_API') ?: '26') as String +} def mobileGlBuildDisaggregatedInproc = { (rootProject.findProperty('mobilegl.buildDisaggregatedInproc') ?: System.getenv('MOBILEGL_BUILD_DISAGGREGATED_INPROC') ?: mobileGlBuildDisaggregated()) as String } @@ -60,7 +67,7 @@ android { compileSdk 34 defaultConfig { - minSdk 26 + minSdk Integer.parseInt(mobileGlAndroidApi()) testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"