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
29 changes: 23 additions & 6 deletions packages/pdfx/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@ rootProject.allprojects {
}
}

// AGP 9 can run with or without built-in Kotlin, so inspect the consuming
// app's explicit setting instead of inferring the mode from the AGP version.
def builtInKotlinEnabled = (project.findProperty('android.builtInKotlin') ?: 'false')
.toString()
.toBoolean()
// AGP 9 compiles Kotlin itself (built-in Kotlin) and fails the build when a
// library subproject applies the Kotlin Gradle Plugin (KGP). Built-in Kotlin is
// on by default on AGP 9+ and can be opted out of with `android.builtInKotlin=false`
// in the consuming app's gradle.properties; on AGP 8 the property has no effect.
// An explicit `false` must be honoured, so the property is checked for presence
// rather than truthiness (Groovy's `?:` would treat `false` as absent), and the
// one resulting boolean drives plugin application and compiler configuration.
// The pluginManager form keeps Flutter's static KGP detection (a text match on
// `apply plugin: 'kotlin-android'`) from flagging this plugin. See
// https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors
def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int
def builtInKotlinProperty = project.findProperty('android.builtInKotlin')
def builtInKotlinEnabled = agpMajor >= 9 &&
(builtInKotlinProperty == null || builtInKotlinProperty.toString().toBoolean())

apply plugin: 'com.android.library'
if (!builtInKotlinEnabled) {
apply plugin: 'kotlin-android'
pluginManager.apply('kotlin-android')
}

android {
Expand Down Expand Up @@ -60,6 +69,14 @@ android {
}
}

if (builtInKotlinEnabled) {
kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11
}
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")
Expand Down