Skip to content

fix: apply kotlin-android when builtInKotlin=false on AGP 9+#102

Open
proninyaroslav wants to merge 1 commit into
acoutts:mainfrom
proninyaroslav:patch-1
Open

fix: apply kotlin-android when builtInKotlin=false on AGP 9+#102
proninyaroslav wants to merge 1 commit into
acoutts:mainfrom
proninyaroslav:patch-1

Conversation

@proninyaroslav

Copy link
Copy Markdown

Problem

Build fails with Could not find method kotlin() (build.gradle:58) when using:

  • AGP 9.x
  • Flutter ≥ 3.44

Flutter 3.44 introduced a migration phase where it automatically sets android.builtInKotlin=false in gradle.properties (via the Flutter migrator tool). This flag disables AGP 9's built-in Kotlin support, so the project still relies on the explicit kotlin-android plugin.

However, the plugin's condition if (agpMajor < 9) skips applying kotlin-android for all AGP 9+ projects — including those where builtInKotlin=false is set. As a result, nobody compiles the plugin's Kotlin sources and FlutterLibphonenumberPlugin class cannot be found at link time.

Fix

  1. Condition: also apply kotlin-android when android.builtInKotlin is explicitly 'false', even on AGP 9+:

    def builtInKotlin = project.findProperty('android.builtInKotlin')
    if (agpMajor < 9 || builtInKotlin == 'false') {
        apply plugin: 'kotlin-android'
    }
    
  2. Guard: wrap the kotlin {} compiler-options block in plugins.withId() so it only executes when the Kotlin plugin is actually present (safe for both the old path and the built-in Kotlin path):

    plugins.withId("org.jetbrains.kotlin.android") {
        kotlin {
            compilerOptions {
                jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
            }
        }
    }

Reproduction

  • Flutter 3.44.1, AGP 9.2.1, Gradle 9.4.1
  • Run flutter clean && flutter build apk
  • Observe: FAILURE … Could not find method kotlin() for arguments on build.gradle:58

After this fix the build succeeds with only a deprecation warning
(expected until downstream projects fully migrate to built-in Kotlin).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant