Skip to content

Commit 9f02639

Browse files
committed
Migrate to declarative Gradle plugin application
Update example app to use the new declarative plugins block instead of imperative apply methods, as required by Gradle 8.x and modern Flutter. Changes: - Migrate settings.gradle to use pluginManagement and plugins blocks - Update app/build.gradle to use plugins block - Fixes "app_plugin_loader Gradle plugin imperatively" error This is required for Gradle 8.1+ compatibility.
1 parent 8c00664 commit 9f02639

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

example/android/app/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ if (flutterVersionName == null) {
2121
flutterVersionName = '1.0'
2222
}
2323

24-
apply plugin: 'com.android.application'
25-
apply plugin: 'kotlin-android'
26-
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
24+
plugins {
25+
id "com.android.application"
26+
id "org.jetbrains.kotlin.android"
27+
id "dev.flutter.flutter-gradle-plugin"
28+
}
2729

2830
android {
2931
compileSdkVersion 34

example/android/settings.gradle

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
include ':app'
1+
pluginManagement {
2+
def flutterSdkPath = {
3+
def properties = new Properties()
4+
file("local.properties").withInputStream { properties.load(it) }
5+
def flutterSdkPath = properties.getProperty("flutter.sdk")
6+
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
7+
return flutterSdkPath
8+
}()
29

3-
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4-
def properties = new Properties()
10+
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
511

6-
assert localPropertiesFile.exists()
7-
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
12+
repositories {
13+
google()
14+
mavenCentral()
15+
gradlePluginPortal()
16+
}
17+
}
818

9-
def flutterSdkPath = properties.getProperty("flutter.sdk")
10-
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11-
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
19+
plugins {
20+
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21+
id "com.android.application" version "8.1.0" apply false
22+
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
23+
}
24+
25+
include ":app"

0 commit comments

Comments
 (0)