Flutter新建插件项目Android里找不到包的问题解决方案

问题:我在试着新建一个flutter插件项目后,去写android代码时发现找不到flutter相关的类


报错如下

去依赖里看看确实没有


依赖库

后来各种百度,Google终于找到了解决方案,原来是新建项目没有默认把到依赖进去

分两步:

1.local.properties文件里配置flutter_sdk


local


2.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'

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容