Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions skipstone/Sources/SkipBuild/Commands/PluginCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Any> {
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
Expand Down
Loading