Flutter插件android模块中的报红处理

2021-05-26  本文已影响0人  李小轰

如图所示,FlutterPlugin中Android模块引用 flutter.jar 内容报红:


image.png

这是由于 flutter.jar 没有被引入造成的,处理方式分为以下三个步骤:

//获取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按钮重新编译即可

上一篇 下一篇

猜你喜欢

热点阅读