Android导入Flutter Module报错Failed to apply plugin class ‘FlutterPlugin’.
最近将Flutter版本升级到2.5.3后发现一个问题,在Android项目中import或new一个Flutter module会提示错误:
Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository ‘maven’ was added by plugin class ‘FlutterPlugin’
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin class ‘FlutterPlugin’.
这个错误在我这里是必现的,所以在此记录一下解决方法,希望能够帮助遇到同样问题的同学。
第一步:
打开Android project的settings.gradle修改repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)为
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
第二步:
打开Android project的build.gradle增加如下设置
allprojects {
repositories {
google()
jcenter()
}
}
第三步:
重新build项目
到这里这个报错问题应该已经解决了,这个应该是flutter的一个bug,希望之后的版本可以解决掉这个问题。