Flutter插件android模块中的报红处理
2021-05-26 本文已影响0人
李小轰
如图所示,FlutterPlugin中Android模块引用 flutter.jar 内容报红:

这是由于 flutter.jar 没有被引入造成的,处理方式分为以下三个步骤:
- local.properties 添加 flutter sdk 路径如 flutter.sdk=/Users/Rex/.fvm/versions/1.22.5-stable
截图示例:image.png - android 目录下 build.gradle 文件添加如下代码
//获取local.properties配置文件
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
//获取flutter的sdk路径
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.")
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
compileOnly files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar")
compileOnly 'androidx.annotation:annotation:1.1.0'
}
截图示例:image.png
点击Sync按钮重新编译即可