Skip to content

Gradle Kotlin DSL support. #93238

Closed
Closed

Description

How should Flutter use Gradle Kotlin DSL?
I got many errors while trying to suggest Groovy to Kotlin.
I saw 33726 but didn't find a solution.

Activity

  1. darshankawar commented on Nov 9, 2021

    @darshankawar
    Member

    @xiao-cao-x
    I am not sure, but the tool may not be supporting the Kotlin DSL yet. Can you provide flutter doctor -v, all related build.gradle files along with error log you get ?

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 9, 2021
  3. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 17, 2021
  4. darshankawar commented on Nov 18, 2021

    @darshankawar
    Member

    all related build.gradle files along with error log you get ?

    @xiao-cao-x Can you provide above ?

  5. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 18, 2021
  6. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 18, 2021
  7. darshankawar commented on Nov 18, 2021

    @darshankawar
    Member

    I tried to find similar / duplicate for this request, but couldn't find any, so keeping it open for further insights on this.

  8. added
    platform-androidAndroid applications specifically
    t: gradle"flutter build" and "flutter run" on Android
    toolAffects the "flutter" command-line tool. See also t: labels.
    and removed
    in triagePresently being triaged by the triage team
    on Nov 18, 2021
  9. 13 remaining items

  10. DRSchlaubi commented on Aug 18, 2023

    @DRSchlaubi
    Contributor
  11. Daphne-CoffeeIT commented on May 31, 2024

    @Daphne-CoffeeIT

    Any updates? From this issue it seems like some things are happening: #121541. But I still have issues and can't use KSP

  12. bartekpacia commented on May 31, 2024

    @bartekpacia
    Member

    @Daphne-CoffeeIT Issue #121541 is unrelated to this one.

  13. Daphne-CoffeeIT commented on May 31, 2024

    @Daphne-CoffeeIT

    @bartekpacia Alright. This issue was most recently mentioned there, so that's why looked for answers there as well. For my case they are related, since I want to migrate from Groovy to Kotlin.

  14. bartekpacia commented on May 31, 2024

    @bartekpacia
    Member

    @Daphne-CoffeeIT Sure! For a very simple example app that is migrated from Gradle Groovy DSL to Gradle Kotlin DSL, check out this one in Flutter repo (link). There are some redundant stuff.

    I can also share buildfiles of my private app that is migrated from Groovy to Kotlin:

    settings.gradle.kts
    pluginManagement {
        val flutterSdkPath = run {
            val properties = java.util.Properties()
            file("local.properties").inputStream().use { properties.load(it) }
            val flutterSdkPath = properties.getProperty("flutter.sdk")
            require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
            flutterSdkPath
        }
    
        includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
    
        repositories {
            google()
            mavenCentral()
            gradlePluginPortal()
        }
    }
    
    plugins {
        id("dev.flutter.flutter-plugin-loader")
    
        // Consult before bumping:
        // https://developer.android.com/studio/releases#android_gradle_plugin_and_android_studio_compatibility
        id("com.android.application") version "8.2.2" apply false
    
        id("org.jetbrains.kotlin.android") version "2.0.0" apply false
        id("com.google.gms.google-services") version "4.4.1" apply false
        id("com.google.firebase.crashlytics") version "2.9.9" apply false
    }
    
    include(":app")
    build.gradle.kts
    rootProject.layout.buildDirectory = file("../build")
    subprojects {
        project.layout.buildDirectory = file(rootProject.layout.buildDirectory.map { "$it/${project.name}" })
    }
    subprojects {
        project.evaluationDependsOn(":app")
    }
    
    tasks.register<Delete>("clean") {
        delete(rootProject.layout.buildDirectory)
    }
    app/build.gradle.kts
    import java.io.FileInputStream
    import java.util.Properties
    
    plugins {
        id("com.android.application")
        id("org.jetbrains.kotlin.android")
        id("dev.flutter.flutter-gradle-plugin")
        id("com.google.gms.google-services")
        id("com.google.firebase.crashlytics")
    }
    
    val keystoreProperties = Properties()
    val keystorePropertiesFile = rootProject.file("keystore.properties")
    if (keystorePropertiesFile.exists()) {
        keystoreProperties.load(FileInputStream(keystorePropertiesFile))
    }
    
    android {
        namespace = "pl.baftek.discoverrudy"
        compileSdk = 34
    
        compileOptions {
            sourceCompatibility = JavaVersion.VERSION_11
            targetCompatibility = JavaVersion.VERSION_11
        }
    
        kotlinOptions {
            jvmTarget = "11"
        }
    
        defaultConfig {
            applicationId = "pl.baftek.discoverrudy"
            minSdk = 21
            targetSdk = 34
            versionCode = flutter.versionCode()
            versionName = flutter.versionName()
        }
    
        signingConfigs {
            create("release") {
                storeFile = if (keystorePropertiesFile.exists()) file(keystoreProperties["storeFile"] as String) else null
                storePassword = if (keystorePropertiesFile.exists()) keystoreProperties["storePassword"] as String else null
                keyAlias = if (keystorePropertiesFile.exists()) keystoreProperties["keyAlias"] as String else null
                keyPassword = if (keystorePropertiesFile.exists()) keystoreProperties["keyPassword"] as String else null
            }
        }
    
        buildTypes {
            named("debug") {
                signingConfig = signingConfigs.getByName("debug")
                isShrinkResources = false
                isMinifyEnabled = false
            }
    
            named("release") {
                signingConfig = signingConfigs.getByName("release")
                isShrinkResources = true
                isMinifyEnabled = true
    
                proguardFiles(
                    getDefaultProguardFile("proguard-android-optimize.txt"),
                    "proguard-rules.pro"
                )
    
                // Add ProGuard ? and Dart mapping files
            }
        }
    }
    
    flutter {
        source = "../.."
    }

    Hope it helps!

  15. Daphne-CoffeeIT commented on May 31, 2024

    @Daphne-CoffeeIT

    @bartekpacia Thanks, but I do have the Kotlin code, that's not the issue. It's just that Flutter and most Flutter tools, for example when running flutterfire configure, don't support it yet. They look for gradle files instead of gradle.kts files. That and millions of other issues show that Flutter currently doesn't (fully) support it yet. And then I read all over the internet that it indeed doesn't, so I migrated back. If you have different information I'd love to see the source!

  16. bartekpacia commented on May 31, 2024

    @bartekpacia
    Member

    Ah, sorry to hear that. At this point it's up to the ecosystem to adapt to Gradle Kotlin DSL.
    I don't see what else Flutter could do here (in addition to providing some guidance for plugin/package authors)

  17. reidbaker commented on Jul 2, 2024

    @reidbaker
    Contributor

    I think our tooling now checks for build.gradle.kts in addition to build.gradle.

    flutterfire issues cant be resolved in this repository. If there is a more specific issue please file it but in general I think the work @bartekpacia did to support kotlin dsl solves this issue.

    Will leave this comment for a bit to see if others disagree then will close this issue.

  18. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 2, 2024
  19. github-actions commented on Jul 23, 2024

    @github-actions

    Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.
    If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.
    Thanks for your contribution.

  20. github-actions commented on Aug 6, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  21. locked as resolved and limited conversation to collaborators on Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityplatform-androidAndroid applications specificallyt: gradle"flutter build" and "flutter run" on Androidteam-androidOwned by Android platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-androidTriaged by Android platform teamwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions