作者:蓝月亮乐悠悠 | 来源:互联网 | 2023-10-17 13:47
在FlutterApp中打开对应的Android工程;并且向Android原生工程添加一个AndroidModule模块,并且在工程根settings.
- 在 Flutter App 中打开 对应的 Android 工程;
- 并且向 Android 原生工程添加 一个 Android Module 模块,并且在 工程根 settings.gradle 配置文件中 添加我们的模块;
- 模块 引用第三方 Lib
dependencies {//百度SDK 依赖implementation fileTree(dir: 'libs', include: ['*.jar'])implementation 'androidx.appcompat:appcompat:1.1.0'implementation 'com.google.android.material:material:1.1.0'testImplementation 'junit:junit:4.+'androidTestImplementation 'androidx.test.ext:junit:1.1.1'androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
这里 爆出一个异常: 整了我小两天
当前项目 找不到 Flutter 所需要的 依赖
Cannot resolve symbol 'MethodChannel';
Add library 'Gradle:io.flutter:flutter_embedding_debugxxxxxxxx
按照网上配置:
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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"....
flutter {source '../..'
}
爆出 另外一个错:
Caused by: org.gradle.api.internal.tasks.DefaultTaskContainer$DuplicateTaskException: Cannot add task 'generateLockfiles' as a task with that name already exists.
直到后来:
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: 'com.android.library'//plugins {
// id 'com.android.library'
//}android {compileSdkVersion 30buildToolsVersion "30.0.3"defaultConfig {minSdkVersion 23targetSdkVersion 30versionCode 1versionName "1.0"testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"consumerProguardFiles "consumer-rules.pro"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'}}compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}
}dependencies {//百度SDK 依赖implementation fileTree(dir: 'libs', include: ['*.jar'])implementation 'androidx.appcompat:appcompat:1.1.0'implementation 'com.google.android.material:material:1.1.0'testImplementation 'junit:junit:4.+'androidTestImplementation 'androidx.test.ext:junit:1.1.1'androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'//android 原生模块依赖 fluttercompileOnly files("$flutterRoot//bin/cache/artifacts/engine/android-arm/flutter.jar")
}