From 486a90d699e053b42d650ffa1986d5759fa3403d Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Thu, 3 Dec 2026 20:44:32 -0800 Subject: [PATCH] Raise app compileSdk to the catalog's minor API level Compose 1.13 requires compileSdk 37.1, but apps generated by skip init set compileSdk = libs.versions.android.sdk.compile.get().toInt(), which can't express a minor API level. When the version catalog has an android-sdk-compilePlatform entry like "37.1" (to be added by skip-unit), skip-build-plugin uses androidComponents.finalizeDsl to set compileSdkMinor on apps whose compileSdk equals that platform's major level and that haven't set a minor level themselves. An explicit compileSdkMinor = 0 opts out. --- .../SkipBuild/Commands/PluginCommand.swift | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/skipstone/Sources/SkipBuild/Commands/PluginCommand.swift b/skipstone/Sources/SkipBuild/Commands/PluginCommand.swift index 1dce0b16..142d9ea6 100644 --- a/skipstone/Sources/SkipBuild/Commands/PluginCommand.swift +++ b/skipstone/Sources/SkipBuild/Commands/PluginCommand.swift @@ -179,12 +179,14 @@ dependencies { /// `SkipGradlePlugins.kt` private func skipGradlePluginContent() -> String { """ +import org.gradle.api.Action import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.initialization.Settings import org.gradle.api.logging.Logger import org.gradle.api.logging.Logging +import org.gradle.api.artifacts.VersionCatalogsExtension import org.gradle.api.plugins.ExtensionAware import org.gradle.api.provider.Property import org.gradle.kotlin.dsl.apply @@ -310,6 +312,34 @@ class SkipBuildPlugin @Inject constructor(private val os: ExecOperations) : Plug } } + // Raise the app's compileSdk to the minor API level from the version catalog's android-sdk-compilePlatform + // (e.g., 37 -> 37.1). Libraries like Compose 1.13 require compileSdk 37.1, but the app's build.gradle.kts + // generated by `skip init` sets `compileSdk = libs.versions.android.sdk.compile.get().toInt()`, which can + // only express the major level. finalizeDsl runs after the app's android block has been evaluated, so this + // sees the app's own settings and only fills in the minor level when the app compiles against the platform's + // major level and hasn't set a minor level itself (so an explicit `compileSdkMinor = 0` opts out). + val libsCatalog = extensions.findByType(VersionCatalogsExtension::class.java)?.find("libs")?.orElse(null) + val catalogCompilePlatform = libsCatalog?.findVersion("android-sdk-compilePlatform")?.orElse(null)?.requiredVersion?.split(".") + val catalogCompileSdk = catalogCompilePlatform?.getOrNull(0)?.toIntOrNull() + val catalogCompileSdkMinor = catalogCompilePlatform?.getOrNull(1)?.toIntOrNull() + if (catalogCompileSdk != null && catalogCompileSdkMinor != null && catalogCompileSdkMinor > 0) { + // the kotlin-dsl plugin compiles Action lambdas with the action's argument as the receiver + val raiseCompileSdkMinor = Action { + val androidExtension = this + androidExtension.withGroovyBuilder { + val compileSdk = getProperty("compileSdk") as Int? + val compileSdkMinor = getProperty("compileSdkMinor") as Int? + if (compileSdk == catalogCompileSdk && compileSdkMinor == null) { + info("Skip: raising compileSdk from ${compileSdk} to ${compileSdk}.${catalogCompileSdkMinor}") + setProperty("compileSdkMinor", catalogCompileSdkMinor) + } + } + } + extensions.getByName("androidComponents").withGroovyBuilder { + "finalizeDsl"(raiseCompileSdkMinor) + } + } + data class DeviceInfo(val serialNumber: String, val deviceType: String) /// Invoke `adb devices` and parse the output for the list of connected devices