Flutter插件Android工程无法识别io.flutter包

目录

成功步骤

只想看方法,直接看成功步骤!!!!

 

新建Flutter插件项目,打开Android工程报红,无法应用io.flutter.xxx

adcc3d3ac8374e87846df2dcfad665d4.png

这是因为android项目中没有依赖Flutter库,经过对比Flutter工程Android下的gardle配置,发现需要应用Flutter SDK下的flutter.gradle,

dac2aea7d48a471186ed68f4a811126e.png

 仿造配置如下

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

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.")
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

结果不行,提示没有:app模块,应为我新建的Flutter插件项目,不是FlutterAPP项目

5091a2067dfa45cfbeead8e9d7bf5675.png

成功步骤

 打开"$flutterRoot/packages/flutter_tools/gradle/“目录发现有个resolve_dependencies.gradle文件,看名子应该是应用依赖,直接将flutter.gradle换成resolve_dependencies.gradle还是失败,最终我将resolve_dependencies.gradle复制到项目中,经过修改再应用到项目中成功运行

f17fefaa3bbe42cbabfa75438eb3cca0.png

 

c87cf57600634f78874b4583042d33d9.png

 resolve_dependencies.gradle内容

import java.nio.file.Paths

//获取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 flutterRootPath = localProperties.getProperty('flutter.sdk')

if (flutterRootPath == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

String storageUrl = System.getenv('FLUTTER_STORAGE_BASE_URL') ?: "https://storage.googleapis.com"

repositories {
    google()
    mavenCentral()
    maven {
        url "$storageUrl/download.flutter.io"
    }
}

File flutterRoot = projectDir.parentFile.parentFile.parentFile

assert flutterRoot.isDirectory()
String engineVersion = Paths.get(flutterRootPath, "bin", "internal", "engine.version")
        .toFile().text.trim()

configurations {
    flutterRelease.extendsFrom releaseImplementation
    flutterDebug.extendsFrom debugImplementation
    flutterProfile.extendsFrom debugImplementation
}

dependencies {
    flutterRelease "io.flutter:flutter_embedding_release:1.0.0-$engineVersion"
    flutterRelease "io.flutter:armeabi_v7a_release:1.0.0-$engineVersion"
    flutterRelease "io.flutter:arm64_v8a_release:1.0.0-$engineVersion"

    flutterProfile "io.flutter:flutter_embedding_profile:1.0.0-$engineVersion"
    flutterProfile "io.flutter:armeabi_v7a_profile:1.0.0-$engineVersion"
    flutterProfile "io.flutter:arm64_v8a_profile:1.0.0-$engineVersion"

    compileOnly "io.flutter:flutter_embedding_debug:1.0.0-$engineVersion"
    compileOnly "io.flutter:armeabi_v7a_debug:1.0.0-$engineVersion"
    compileOnly "io.flutter:arm64_v8a_debug:1.0.0-$engineVersion"
    compileOnly "io.flutter:x86_debug:1.0.0-$engineVersion"
    compileOnly "io.flutter:x86_64_debug:1.0.0-$engineVersion"
}

 切记不要保留task resolveDependencies...,否则会应用失败

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值