VS Code flutter - android setup

In VS Studio I have a hard time to setup the android section including build.gradle.kts and settings.gradle. How to default it or update to newest content inside those myApp>android files. It started to get messy after trying to combine Java and gradle versions manually, which seemed to be necessary. I hope, there will be some easier way.

Thank you!

Debug console shows this:

FAILURE: Build failed with an exception.

* Where:

Settings file ‘/Users/[myUser]/dev/[myApp]/android/settings.gradle.kts’ line: 23

* What went wrong:

Script compilation errors:

Line 23:     id “dev.flutter.flutter-plugin-loader” version “1.0.0”


              ^ Unexpected tokens (use ';' to separate expressions on the same line)

Line 23:     id “dev.flutter.flutter-plugin-loader” version “1.0.0”

           ^ Function invocation 'id(...)' expected

Line 23:     id “dev.flutter.flutter-plugin-loader” version “1.0.0”

           ^ No value passed for parameter 'id'

Line 24:     id “com.android.application” version “{7.3.0}” apply false

              ^ Unexpected tokens (use ';' to separate expressions on the same line)

Line 24:     id “com.android.application” version “{7.3.0}” apply false

           ^ Function invocation 'id(...)' expected

Line 24:     id “com.android.application” version “{7.3.0}” apply false

           ^ No value passed for parameter 'id'

Line 25:     id “org.jetbrains.kotlin.android” version “{1.7.10}” apply false

              ^ Unexpected tokens (use ';' to separate expressions on the same line)

Line 25:     id “org.jetbrains.kotlin.android” version “{1.7.10}” apply false

           ^ Function invocation 'id(...)' expected

Line 25:     id “org.jetbrains.kotlin.android” version “{1.7.10}” apply false

           ^ No value passed for parameter 'id'

settings.gradle.kts file:

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” version “1.0.0” // apply true
    id “com.android.application” version “{7.3.0}” apply false
    id “org.jetbrains.kotlin.android” version “{1.7.10}” apply false
}

include “:app”

You mix Groovy DSL syntax and Kotlin DSL syntax in a Kotlin DSL file and get complaint that this is not valid syntax of course.

1 Like

@Vampire Thank you for your quick response!

I see. Well, for me it would be interesting to get the flutter app updated and learning a bit about these things.

After some investigation, I found, that certain gradle versions only work with certain Java versions based on the errors shown in the console. This was the intend to change these files manually.

If there is a chance to get some clues about it, I would appreciate your help. To my understanding, changes seem to be necessary in the android files section from VS Code to run on a physical device. The simulators work fine, though

Thank you very much!

PS: As a guitar player learning flutter, I would like to work out the customing of the android section in this project with your kind support

I found, that certain gradle versions only work with certain Java versions

That’s correct, here is the compatibility table: Compatibility Matrix

based on the errors shown in the console.

No idea what you see, all you showed only says “don’t use Groovy DSL in a Kotlin DSL file”.

I personally strongly recommend using a proper IDE, and even if just to edit the build scripts. A good IDE like IntelliJ IDEA or Android Studio gives you very good authoring support. VSC is imho “just” a fancy editor that can me enriched with some minimal IDE-like functionality, but can in no way compete with a real IDE.

This was the intend to change these files manually.

Writing build scripts manually is imho the most sensible way anyway. :smiley:
Just don’t try to write Groovy in a Kotlin file.
That is like trying to write Python in a Kotlin file, it will not compile.

If there is a chance to get some clues about it, I would appreciate your help.

About what? Just ask.

To my understanding, changes seem to be necessary in the android files section from VS Code to run on a physical device. The simulators work fine, though

I have no idea what changes you talk about.
Also, this is a Gradle from, not an Android community and I don’t do Android dev.
I also have no idea what “the android files section from VSC” would contain, even if I would do Android, I wouldn’t waste my lifetime with VSC when I can also use IJ or AS. :slight_smile: Besides that this is also not a VSC community. :slight_smile:

1 Like

@Vampire Allright, will try Android Studio. The main question seems to be how to apply gradle compatibility into flutter development. But: This necessity only appears in that particular above mentioned guitar chord project (in VS Code). Will check out Android Studio and - in case - would come back later with more detailed console outputs and better knowledge, I hope :upside_down_face: . … Again: Thanks for your help!!

EDIT:

This was the flutter help page link that I followed, suggesting changing the sensible inner workings. I tried it twice to the best of my abilities, but was unfortunate. The reason to dive into this was, not to be able to only change the gradle version in the gradle-wrapper-properties file from the flutter>android file section anymore. As far as I understand it, due to a deprecatin of the “imperative method” to apply a newer gradle version. I tried to apply gradle v8.5 to java v21

how to apply gradle compatibility into flutter development

I’m sorry, but I have no idea what you mean with that statement.

This was the flutter help page link that I followed,

Well yeah, for whatever reason that article shows Groovy DSL code. To use it in your Kotlin DSL file you need to translate it to Kotlin DSL, or find a variant of that article that shows Kotlin DSL instead, or also look at the manual where you can switch between Kotlin DSL examples and Groovy DSL examples.

As far as I understand it, due to a deprecatin of the “imperative method” to apply a newer gradle version.

Gradle still supports the “imperative” method to apply a plugin, it is just legacy and discouraged since many years and versions already.
It is the Flutter plugin which stopped encouraging that bad practice and deprecated the imperative way to apply it.

sure, that is true, should rephrase it: how to properly apply gradle versions into flutter.

Thank you for the insights. Regarding the imperative method: I just changed the version number from 7.1.0 to 8.5 and got an error message referencing to the deprecated imperative method from flutter (as said in VS Code). I did this several times BEFORE applying the more delicate changes inside the files from the flutter help section. Not sure, what I am doing wrong. I am sure there will be an easier fix.

how to properly apply gradle versions into flutter.

I’m really sorry, but I still have no idea what you try to say. To “apply gradle versions into flutter” does not really have any meaning I’m aware of. If you mean how to use different Gradle versions in a Flutter project, you probably should ask in Flutter community instead.

and got an error message referencing to the deprecated imperative method from flutter

Maybe you should share the concrete message. Details are important, especially with such demands for information. Optimally, the information is shared in form of a build --scan URL if possible.

Not sure, what I am doing wrong. I am sure there will be an easier fix.

Maybe if you share the error. What you do wrong I said. You copied snippets meant for a ...gradle file into a ...gradle.kts file. Different programming language => compile error.

1 Like

It is a flutter thing. I suggest to stop the discussion here, as the question (different language=compile error) is already properly answered very clear. Again: Big Thank You for your time and patience @Vampire

Here is a link referencing to the implementation topic in more detail from 2023, not sure if it is still valid…Anyways would be content for another thread.

1 Like