flutter / website

Flutter documentation web site
https://docs.flutter.dev
Other
2.74k stars 3.17k forks source link

Clarify which value should be updated on 'Required Kotlin version' page #10380

Open Bizarrus opened 2 months ago

Bizarrus commented 2 months ago

Page URL

https://docs.flutter.dev/release/breaking-changes/kotlin-version/

Page source

https://github.com/flutter/website/tree/main/src/content/release/breaking-changes/kotlin-version.md

Describe the problem

I've get following error:

[!WARNING] ┌─ Flutter Fix ──────────────────────────────────────────────────────────────────┐ │ [!] Your project requires a newer version of the Kotlin Gradle plugin. │ │ Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then │ │ update F:\\android\build.gradle: │ │ ext.kotlin_version = '' │ └──────────────────────────────────────────────────────────────────────────┘

But ext.kotlin_version never exists in <Project>\android\build.gradle:

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

<Project>\android\app\build.gradle:

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

android {
    namespace "com.example.whatsnear"
    compileSdk flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "de.whatsnear"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {}

Expected fix

No response

Additional context

No response

I would like to fix this problem.

parlough commented 2 months ago

Thanks for the issue. I'm not familiar with this area, so I'll defer to others :)

Could you let us know your Flutter version and setup by sharing the output of flutter doctor --verbose?

@bartekpacia Do you have any ideas here? Perhaps this older migration guide needs to link somewhere else, mention another file, or include another potential solution?

bartekpacia commented 2 months ago

Thanks for the ping @parlough :)

The Flutter Fix (and the migraton guide) should also mention the newer, modern place where Kotlin version is configured - in the android/settings.gradle file, in the plugins {} block, as explained here, eg:

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.3.1" apply false
    id "org.jetbrains.kotlin.android" version "1.9.22" apply false
}
Bizarrus commented 2 months ago

The Flutter Fix (and the migraton guide) should also mention the newer, modern place where Kotlin version is configured - in the android/settings.gradle file, in the plugins {} block, as explained here, eg:

So the definition of the version no longer runs via the variable ext.kotlin_version, but directly as mentioned in the plugin section as Depencies?

From which version is this behavior like this? There is no information on this.

Perhaps you should adapt the warning message and the URL referred to there to this effect, as this simply leads to misunderstandings: you are searching for the variable to death.

This is very confusing, especially for new flutter developers like me: You install the very latest version and start with it, but you get old error messages that have to be handled completely differently in the current version. Especially here, you don't think about the fact that you have to fall back on a migration guide because you are using the latest version.

bartekpacia commented 2 months ago

I'm sorry for your bad experience. It's a huge project and when some part is updated (as in this case), it's hard to know about all the other places where it's referred. Thanks for reporting it.

So the definition of the version no longer runs via the variable ext.kotlin_version, but directly as mentioned in the plugin section as Depencies?

This is correct.

From which version is this behavior like this?

I think since Flutter 3.16. To see how default Gradle buildscripts differ across Flutter versions, take a look at this issue. If you have generated your project with an older version of Flutter, it's advisable to upgrade your buildscripts to the newest form.

If you have any further problems let me know, I'll do my best to help.

Bizarrus commented 2 months ago

Okay, like commit #0984a7f (two weeks ago), the messages was changed:

https://github.com/flutter/flutter/blob/74b65d4e4c6190fedd76e02c83196688ac149467/packages/flutter_tools/lib/src/android/gradle_errors.dart#L448-L454

I think, the changes are currently not on the VS Code-Plugin.

My Version is:

Flutter 3.19.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 300451adae (2 weeks ago) • 2024-03-27 21:54:07 -0500
Engine • revision e76c956498
Tools • Dart 3.3.3 • DevTools 2.31.1
bartekpacia commented 2 months ago

I think, the changes are currently not on the VS Code-Plugin.

FYI, this is unrelated to Flutter VSCode plugin.

The bug is inside flutter_tools package, which is basically the flutter command-line program.