Android中集成flutter组件,按照官方文档进行:
// 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
在按照官方文档操作之后,报错:Failed to apply plugin class ‘FlutterPlugin‘.
针对上面的报错,处理方式如下(该处理方式参照自https://github.com/flutter/flutter/issues/99735):
- step1: 创建flutter_settings.gradle文件,和setting.gradle在同一个目录下
setBinding(new Binding([gradle: this]))
evaluate(new File(settingsDir.parentFile, 'flutter_module/.android/include_flutter.groovy'))
备注:flutter_module修改为自己的flutter依赖名称
eg:
setBinding(new Binding([gradle: this]))
evaluate(new File(settingsDir.parentFile, 'MySWApp/lib_flutter/.android/include_flutter.groovy'))
step2: 修改settings.gradle文件
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "MySWApp"
include ':app'
apply { from("flutter_settings.gradle") } // add this
重新运行就OK了
参考文档:https://blog.csdn.net/wanggang514260663/article/details/124934520