FireFlutter依赖引发Kotlin-Gradle插件版本不兼容问题求助
解决Flutter项目导入后Gradle依赖版本冲突问题
问题核心
你的项目因FireFlutter依赖间接引入的sign_in_with_apple插件要求kotlin-gradle-plugin:1.3.50,但该旧版本与当前项目的Gradle配置、compileSdk版本不兼容,导致构建失败。移除FireFlutter虽能构建,但会丢失通知功能,必须通过统一依赖版本来解决冲突。
解决方案
1. 统一根目录build.gradle的Kotlin版本
找到项目根目录下的build.gradle文件(非app模块下的),在buildscript块中明确指定与compileSdk 33兼容的Kotlin版本,替换动态版本:
buildscript { ext.kotlin_version = '1.7.20' // 推荐1.7.x系列,适配compileSdk 33 repositories { google() mavenCentral() } dependencies { classpath "com.android.tools.build:gradle:7.4.2" // 确保Gradle版本与Kotlin版本匹配 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.15' } }
2. 强制所有依赖使用统一Kotlin版本
在你提供的app模块build.gradle中,添加版本强制策略,避免依赖间的版本冲突:
在android块内插入:
configurations.all { resolutionStrategy { force "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" force "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" } }
3. 更新FireFlutter到最新稳定版
打开pubspec.yaml,将FireFlutter依赖更新到官方最新稳定版,新版通常会修复依赖兼容问题:
dependencies: fireflutter: ^最新稳定版本号
4. 彻底清理缓存并重新构建
执行以下命令清除旧缓存,确保依赖完全刷新:
flutter clean # Windows用户删除C:\Users\你的用户名\.gradle\caches rm -rf ~/.gradle/caches flutter pub get cd android && ./gradlew clean build --refresh-dependencies
修改后的app模块build.gradle参考
关键修改后的完整文件如下:
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.") } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '26' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.1.2' } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply plugin: 'applovin-quality-service' applovin { apiKey "**********" } def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) } android { compileSdkVersion 33 ndkVersion flutter.ndkVersion // 添加版本强制策略 configurations.all { resolutionStrategy { force "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" force "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { applicationId "*********" minSdkVersion 23 targetSdkVersion 31 versionCode 26 versionName "1.1.2" multiDexEnabled true } signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null storePassword keystoreProperties['storePassword'] } } buildTypes { release { signingConfig signingConfigs.release } } dexOptions { javaMaxHeapSize "2G" } } flutter { source '../..' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'com.google.android.gms:play-services-ads:21.1.0' implementation 'com.android.support:multidex:1.0.3' implementation 'com.applovin:applovin-sdk:+' } apply plugin: 'com.google.gms.google-services'
内容的提问来源于stack exchange,提问作者Zedicus Ténèbres
相关产品推荐
相关产品推荐

