Flutter新建插件項(xiàng)目Android里找不到包的問(wèn)題解決方案

問(wèn)題:我在試著新建一個(gè)flutter插件項(xiàng)目后,去寫(xiě)android代碼時(shí)發(fā)現(xiàn)找不到flutter相關(guān)的類(lèi)


報(bào)錯(cuò)如下

去依賴?yán)锟纯创_實(shí)沒(méi)有


依賴庫(kù)

后來(lái)各種百度,Google終于找到了解決方案,原來(lái)是新建項(xiàng)目沒(méi)有默認(rèn)把到依賴進(jìn)去

分兩步:

1.local.properties文件里配置flutter_sdk


local


2.build.gradle文件里添加依賴庫(kù)


依賴

//獲取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'

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容