Skip to content

Flutter Gradle Plugin 1.0.0 doesn't include plugin dependencies in compile classpath #179623

@mkamdar

Description

@mkamdar

Steps to reproduce

Flutter Plugin Dependencies Not Included in Gradle Compile Classpath

Issue Summary

Flutter plugin dependencies are not being automatically included in the Gradle compile classpath when using Flutter Gradle Plugin 1.0.0 with Flutter 3.38.4, Gradle 8.10, and Android Gradle Plugin 8.7.0. This causes compilation errors in GeneratedPluginRegistrant.java where plugin classes cannot be found.

Environment Details

  • Flutter Version: 3.38.4 (stable channel)
  • Dart Version: 3.10.3
  • Flutter Engine: a5cb963 (revision a5cb963)
  • Gradle Version: 8.10
  • Android Gradle Plugin: 8.7.0
  • Kotlin Version: 2.1.0
  • Java Compatibility: 17
  • Operating System: Windows 11 (Version 10.0.26100.7171)
  • Flutter Gradle Plugin: 1.0.0

Steps to Reproduce

  1. Create a Flutter project with plugins (e.g., camera, firebase_analytics, image_picker)
  2. Upgrade to Flutter 3.38.4
  3. Upgrade Gradle to 8.10 and Android Gradle Plugin to 8.7.0
  4. Configure settings.gradle to use the new declarative Flutter Gradle plugin:
    pluginManagement {
        def flutterSdkPath = {
            def properties = new Properties()
            file("local.properties").withInputStream { properties.load(it) }
            def flutterSdkPath = properties.getProperty("flutter.sdk")
            assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
            return flutterSdkPath
        }()
        settings.ext.flutterSdkPath = flutterSdkPath()
        includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
        plugins {
            id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
        }
    }
  5. Apply the plugin in app/build.gradle:
    plugins {
        id "com.android.application"
        id "kotlin-android"
        id "dev.flutter.flutter-gradle-plugin"
    }
  6. Run flutter pub get (succeeds)
  7. Run flutter build apk --debug or ./gradlew :app:assembleDebug

Expected Behavior

The Flutter Gradle plugin should automatically:

  1. Detect Flutter plugins from pubspec.yaml
  2. Include plugin dependencies in the Gradle compile classpath
  3. Allow GeneratedPluginRegistrant.java to compile successfully without errors

Actual Behavior

The build fails with compilation errors indicating that plugin packages cannot be found:

D:\<>\workspace\<>\Mobile\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java:19: error: package io.flutter.plugins.camera does not exist
      flutterEngine.getPlugins().add(new io.flutter.plugins.camera.CameraPlugin());
                                                                   ^
D:\<>\workspace\<>\Mobile\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java:24: error: package io.flutter.plugins.firebase.analytics does not exist
D:\<>\workspace\<>\Mobile\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java:29: error: package io.flutter.plugins.firebase.core does not exist
D:\<>\workspace\<>\Mobile\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java:34: error: package io.flutter.plugins.firebase.messaging does not exist
... (and more plugin errors)

Error Details

Compilation Errors

All Flutter plugin classes referenced in GeneratedPluginRegistrant.java cannot be resolved:

  • io.flutter.plugins.camera.CameraPlugin
  • io.flutter.plugins.firebase.analytics.FlutterFirebaseAnalyticsPlugin
  • io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin
  • io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin
  • com.fluttercandies.flutter_image_compress.ImageCompressPlugin
  • com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin
  • io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin
  • io.github.ponnamkarthik.toast.fluttertoast.FlutterToastPlugin
  • io.flutter.plugins.imagepicker.ImagePickerPlugin
  • io.flutter.plugins.pathprovider.PathProviderPlugin
  • com.tekartik.sqflite.SqflitePlugin
  • io.flutter.plugins.urllauncher.UrlLauncherPlugin

Dependency Resolution Status

  • ✅ Flutter embedding dependencies are resolved correctly:
    • io.flutter:flutter_embedding_debug:1.0.0-a5cb96369ef86c7e85abf5d662a1ca5d89775053
  • ✅ Firebase dependencies are resolved correctly (via BoM)
  • ❌ Flutter plugin dependencies are NOT included in compile classpath
  • ✅ Plugins are detected by Flutter (flutter pub get succeeds)
  • .flutter-plugins-dependencies file is generated correctly
  • GeneratedPluginRegistrant.java is generated correctly

Configuration Files

android/settings.gradle

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }
    settings.ext.flutterSdkPath = flutterSdkPath()

    includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

    plugins {
        id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
    }
}

include ":app"

android/app/build.gradle (relevant sections)

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

android {
    namespace "com.fmbdublin.saiftech"
    compileSdkVersion 34
    // ... other config
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = '17'
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:2.1.0"
    debugImplementation "io.flutter:flutter_embedding_debug:1.0.0-a5cb96369ef86c7e85abf5d662a1ca5d89775053"
    // ... Firebase dependencies
}

android/build.gradle

buildscript {
    ext.kotlin_version = '2.1.0'
    repositories {
        mavenCentral()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.7.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.4.2'
    }
}

allprojects {
    repositories {
        mavenCentral()
        google()
        def flutterSdkPath = {
            def properties = new Properties()
            file("local.properties").withInputStream { properties.load(it) }
            def flutterSdkPath = properties.getProperty("flutter.sdk")
            assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
            return flutterSdkPath
        }()
        maven {
            url "${flutterSdkPath}/bin/cache/artifacts/engine"
        }
    }
}

Plugins Affected

All Flutter plugins with Android implementations are affected. In this project:

  • camera_android (0.10.9+17)
  • firebase_analytics (10.2.1)
  • firebase_core (2.11.0)
  • firebase_messaging (14.5.0)
  • flutter_image_compress_common (1.0.5)
  • flutter_local_notifications (18.0.1)
  • flutter_plugin_android_lifecycle (2.0.23)
  • fluttertoast (8.2.8)
  • image_picker_android (0.8.12+18)
  • path_provider_android (2.2.14)
  • sqflite_android (2.4.0)
  • url_launcher_android (6.3.14)

Workarounds Attempted

  1. ✅ Explicitly added Flutter embedding dependencies (works)
  2. ✅ Added Flutter Maven repository (doesn't help - plugins aren't in Maven)
  3. ✅ Cleaned and regenerated plugin configuration (flutter clean, flutter pub get)
  4. ✅ Verified .flutter-plugins-dependencies file is correct
  5. ❌ Manually adding plugin dependencies would be error-prone and not maintainable

Impact

  • Severity: High - Blocks all Android builds using Flutter plugins
  • Affected Users: Anyone upgrading to Flutter 3.38.4 with the new Gradle plugin system
  • Workaround: None available without manually managing plugin dependencies

Additional Information

  • The issue occurs specifically with the new declarative Flutter Gradle plugin system (version 1.0.0)
  • The old imperative apply from method was removed as deprecated
  • Flutter embedding dependencies work correctly, suggesting the plugin system is partially functional
  • Plugin detection works (flutter pub get succeeds), but dependency inclusion fails

Related Issues

This appears to be related to the migration from the old imperative Gradle plugin system to the new declarative system introduced in Flutter 3.x.

Gradle Version Output

Gradle 8.10
Build time:    2024-08-14 11:07:45 UTC
Revision:      fef2edbed8af1022cef44d4c0514c5f89d7b78
Kotlin:        1.9.24
Groovy:        3.0.22
Ant:           Apache Ant(TM) version 1.10.14 compiled on August 16 2023
Launcher JVM:  21.0.9 (Oracle Corporation 21.0.9+7-LTS-338)
Daemon JVM:    C:\Program Files\Java\jdk-21
OS:            Windows 11 10.0 amd64

Expected results

Expected Behavior

The Flutter Gradle plugin should automatically:

  1. Detect Flutter plugins from pubspec.yaml
  2. Include plugin dependencies in the Gradle compile classpath
  3. Allow GeneratedPluginRegistrant.java to compile successfully without errors

Actual results

Actual Behavior

The build fails with compilation errors indicating that plugin packages cannot be found:

D:\<>\workspace\<>\Mobile\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java:19: error: package io.flutter.plugins.camera does not exist
      flutterEngine.getPlugins().add(new io.flutter.plugins.camera.CameraPlugin());
                                                                   ^
D:\<>\workspace\<>\Mobile\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java:24: error: package io.flutter.plugins.firebase.analytics does not exist
D:\<>\workspace\<>\Mobile\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java:29: error: package io.flutter.plugins.firebase.core does not exist
D:\<>\workspace\<>\Mobile\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java:34: error: package io.flutter.plugins.firebase.messaging does not exist
... (and more plugin errors)

Code sample

Configuration Files

android/settings.gradle

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }
    settings.ext.flutterSdkPath = flutterSdkPath()

    includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

    plugins {
        id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
    }
}

include ":app"

android/app/build.gradle (relevant sections)

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

android {
    namespace "com.fmbdublin.saiftech"
    compileSdkVersion 34
    // ... other config
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = '17'
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:2.1.0"
    debugImplementation "io.flutter:flutter_embedding_debug:1.0.0-a5cb96369ef86c7e85abf5d662a1ca5d89775053"
    // ... Firebase dependencies
}

android/build.gradle

buildscript {
    ext.kotlin_version = '2.1.0'
    repositories {
        mavenCentral()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.7.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.4.2'
    }
}

allprojects {
    repositories {
        mavenCentral()
        google()
        def flutterSdkPath = {
            def properties = new Properties()
            file("local.properties").withInputStream { properties.load(it) }
            def flutterSdkPath = properties.getProperty("flutter.sdk")
            assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
            return flutterSdkPath
        }()
        maven {
            url "${flutterSdkPath}/bin/cache/artifacts/engine"
        }
    }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Flutter Doctor Output

[√] Flutter (Channel stable, 3.38.4, on Microsoft Windows [Version 10.0.26100.7171], locale en-US)
[√] Windows Version (11 Pro 64-bit, 24H2, 2009)
[√] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.3)
[√] Connected device (4 available)
[√] Network resources

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: invalidIssue is closed as not valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions