skip to Main Content

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.

2

Answers


  1. It is necessary to migrate the project if it was created on an older version. Here are the instructions: https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply.

    Login or Signup to reply.
  2. Since Flutter 3.16, projects generated with flutter create use the Plugin DSL to apply Gradle plugins. Projects created with versions of Flutter prior to 3.16 need to be migrated manually.

    To Follow The steps:

    Step one :
    Replace the contents of /android/settings.gradle with the below

    Moving (Plugins) Section to new Below one Out of pluginManagement curly Brackets

    plugins {
        id "dev.flutter.flutter-plugin-loader" version "1.0.0"
        id "com.android.application" version "7.3.0" apply false
        id "org.jetbrains.kotlin.android" version "1.9.22" apply false // Newer Version
    }
    

    Add this Section to pluginManagement Below Line >>

    includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
    
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
    

    Step Two:
    Remove the whole buildscript block from <app-src/android/build.gradle:

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

    Step Three:
    Remove this code if it’s found from <app-src/android/build.gradle:

    -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.")
    -}
    
    -apply plugin: 'com.android.application'
    -apply plugin: 'kotlin-android'
    -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
    

    Last Step : in the same file at first line add this code :

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

    Finally You can follow instructions From Flutter Docs:
    Deprecated imperative apply of Flutter’s Gradle plugins

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search