Flutter采坑系列之:Failed to apply plugin class 'FlutterPlugin'.

1,223 阅读1分钟

最近由于又想重新研究下Flutter相关技能,由于android studio升级到了最新版,创建项目默认使用 id 'com.android.library' version '7.2.0' apply false

module依赖参照官方文档进行:

// Include the host app project.
include ':app'                                    // assumed existing content
setBinding(new Binding([gradle: this]))                                // new
evaluate(new File(                                                     // new
  settingsDir.parentFile,                                              // new
  'my_flutter/.android/include_flutter.groovy'                         // new
))                                                                     // new

在按照官方文档操作之后,报出了如下错误 在这里插入图片描述 针对上面的报错,处理方式如下(该处理方式参照自https://github.com/flutter/flutter/issues/99735):

  • step1: 创建flutter_settings.gradle文件
setBinding(new Binding([gradle: this]))
evaluate(new File(settingsDir.parentFile, 'flutter_module/.android/include_flutter.groovy'))
  • step2: 修改settings.gradle文件
pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
   //repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
  repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) // edit this
    repositories {
        google()
        mavenCentral()

        String flutterStorageUrl = System.getenv("FLUTTER_STORAGE_BASE_URL") ?: "https://storage.googleapis.com"
        maven {
            url flutterStorageUrl + "/download.flutter.io"
        }
}
rootProject.name = "FlutterTestModule"
include ':app'

apply { from("flutter_settings.gradle") } // add this

然后重新build运行,就可以看到正常的效果了。 在这里插入图片描述