You are applying Flutter’s app_plugin_loader Gradle plugin imperatively using

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.

上面这个错误会在flutter 版本升级到3.16+版本时,运行 android上出现提示。

在 Flutter 3.16 中,添加了对使用 Gradle 的 声明性插件 {} 块(也称为 Plugin DSL)应用这些插件的支持,现在它是推荐的方法。从 Flutter 3.16 开始, flutter create使用 Plugin DSL 生成的项目来应用 Gradle 插件。使用3.16之前的Flutter版本创建的项目需要手动迁移。

我目前是升级到 v3.19.5 版本,废话不多说直接上解决方案。

主要修改以下3个gradle文件路径:

  <your-project-root>/android/settings.gradle
  <your-project-root>/android/build.gradle
  <your-project-root>/android/app/build.gradle

android/app/build.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")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

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.7.10" apply false
}

include ":app"

android/build.gradle

找到 buildscript 标签,直接删除(包含标签和里面的内容一起删掉)。

android/app/build.gradle

  1. 删除以下代码:
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.")
}
  1. 在该文件最顶部添加以下代码:
plugins {
  id "com.android.application"
  id "kotlin-android"
  id "dev.flutter.flutter-gradle-plugin"
}

到此,如果你之前没有使用过任何的需要在上面3个gradle文件中配置的插件,按照上面这样的修改,再次运行就不会再报出现红色警告了。

其他第三方插件配置

我使用了sharesdk 下面是配置。 如果你使用了其他插件参考下面三张图在指定位置加上相关配置即可:

You are applying Flutter's app_plugin_loader Gradle plugin imperatively using

You are applying Flutter's app_plugin_loader Gradle plugin imperatively using

You are applying Flutter's app_plugin_loader Gradle plugin imperatively using


结束,祝你顺利。🎉

官方资料参考: 点我

原文链接:https://juejin.cn/post/7351624415317262351 作者:giants

(0)
上一篇 2024年3月30日 上午10:53
下一篇 2024年3月30日 上午10:58

相关推荐

发表回复

登录后才能评论