Skip to content

Flutter incompatible with Android Gradle Kotlin DSL #33762

@janheinrichmerker

Description

@janheinrichmerker

Steps to Reproduce

  1. Create new Flutter Android app.
  2. Mitgrate Gradle build scripts to Kotlin scripts (build.gradle -> build.gradle.kts)
  3. Run flutter run

Logs

> flutter run
Launching lib/main.dart on Pixel 2 in debug mode...
No application found for TargetPlatform.android_arm64.
Is your project missing an android\AndroidManifest.xml?
Consider running "flutter create ." to create one.
> flutter analyze
Analyzing sudoku...
No issues found! (ran in 2.2s)
> flutter doctor -v
[√] Flutter (Channel stable, v1.5.4-hotfix.2, on Microsoft Windows [Version 10.0.17134.765], locale de-DE)
    • Flutter version 1.5.4-hotfix.2 at C:\Users\kiese\AppData\Local\flutter
    • Framework revision 7a4c33425d (5 weeks ago), 2019-04-29 11:05:24 -0700
    • Engine revision 52c7a1e849
    • Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)


[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\kiese\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Users\kiese\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\183.5522156\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[√] Android Studio (version 3.4)
    • Android Studio at C:\Users\kiese\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\183.5522156
    • Flutter plugin version 36.0.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[√] IntelliJ IDEA Ultimate Edition (version 2019.1)
    • IntelliJ at C:\Users\kiese\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\191.7479.19
    • Flutter plugin version 35.3.3
    • Dart plugin version 191.7221

[√] VS Code, 64-bit edition (version 1.34.0)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.0.2

[√] Connected device (1 available)
    • Pixel 2 • FA7A61A10729 • android-arm64 • Android 9 (API 28)

• No issues found!

Possible Causes

When Flutter tries to run the application, it detects, the device is an Android phone.
Then it creates an instance of an AndroidProject.

In the AndroidProject multiple times the assertion is made, that a Gradle project must have a build.gradle file. This assertion is wrong, as Gradle projects can also use the Kotlin DSL, hence use a build.gradle.kts file.

Occurrences to be fixed.

bool get isUsingGradle {
return hostAppGradleRoot.childFile('build.gradle').existsSync();
}

String get applicationId {
final File gradleFile = hostAppGradleRoot.childDirectory('app').childFile('build.gradle');
return _firstMatchInFile(gradleFile, _applicationIdPattern)?.group(1);
}

String get group {
final File gradleFile = hostAppGradleRoot.childFile('build.gradle');
return _firstMatchInFile(gradleFile, _groupPattern)?.group(1);
}

Generally the current approach using Regexes to check the Android project properties is very error-prone. We might investigate whether there are better alternatives.

Workaround

For now you can fix the build by include a build.gradle file referencing the build.gradle.kts file:

apply from: "build.gradle.kts"

This will work around the check in isUsingGradle, but won't fix the other occurences.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions