After Upgrading the Flutter version to 3.19.0
I am getting this warning when running the app:
You are applying Flutter's app_plugin_loader Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply
You are applying Flutter's main Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply
How to remove these deprecated gradle settings.
I have solved the problem by following instructions from Flutter Docs: https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply
Here is what i have done:
Firstly, I have completely replaced android/settings.gradle
file like this:
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
}()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "{agpVersion}" apply false
id "org.jetbrains.kotlin.android" version "{kotlinVersion}" apply false
}
include ":app"
Then, inside the android/settings.gradle
file more specifically inside plugins{}
I have changed {agpVersion}
with 7.2.0
and {kotlinVersion}
with 1.7.20
Then, i have removed the whole buildscript{}
from android/build.gradle
file. Now the android/build.gradle
looks like this:
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Then inside the android/app/build.gradle
file i have deleted some lines. Those lines are,
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with
flutter.sdk in the local.properties file.")
}
and,
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
Then also in this file i have added some lines at the top. Those lines are,
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}
And lastly, inside dependencies{}
of android/app/build.gradle
i also replaced $kotlin_version
with 1.7.20
So, Now the android/app/build.gradle
file looks like this:
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
android {
compileSdkVersion flutter.compileSdkVersion
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID
(https://developer.android.com/studio/build/application-id.html).
applicationId "com.fahad.app"
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
// See the updated portion of the answer if you're using a more recent version of Flutter and Dart.
dependencies {
// Eliminate this line (or the entire dependencies block)
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20"
}
So, I just edited 3 files [android/settings.gradle
], [android/build.gradle
] and [android/app/build.gradle
] and the issue is resolved. Hope this helps.
It's necessary to make one more small adjustment. You need to remove the dependency "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
from android/app/build.gradle
after upgrading to Flutter 3.22 and Dart 3.4. Please refer to this section of the migration guide. Additionally, have a look at this line.