You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter集成flutter_stripe后Kotlin版本不兼容编译失败求助

解决flutter_stripe集成后的Kotlin版本不兼容编译错误

1. 匹配Kotlin Gradle插件与Gradle版本

Kotlin版本和Gradle版本存在严格对应关系,盲目升级到最新Kotlin版本(如2.0.0)可能与当前Gradle版本冲突,先确认对应关系:

  • Kotlin 1.9.x 对应 Gradle 8.0+
  • Kotlin 1.8.x 对应 Gradle 7.3+
  • Kotlin 1.7.x 对应 Gradle 7.0+

2. 统一项目Kotlin版本配置

  • 打开项目根目录下的build.gradle文件,找到ext.kotlin_version,设置为与stripe_android元数据匹配的版本(比如提示的1.9.0对应Kotlin 1.9.x系列,推荐1.9.20):
    buildscript {
        ext.kotlin_version = '1.9.20'
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath "com.android.tools.build:gradle:8.2.0" // 确保此Gradle版本与Kotlin版本匹配
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
  • 检查android/app/build.gradle,确保没有单独设置不同的Kotlin版本,保持与根目录配置一致。

3. 强制所有依赖使用统一Kotlin版本

部分第三方依赖可能自带不同Kotlin版本,在android/build.gradle中添加强制配置:

subprojects {
    afterEvaluate { project ->
        if (project.hasProperty("android")) {
            android {
                compileOptions {
                    sourceCompatibility JavaVersion.VERSION_17
                    targetCompatibility JavaVersion.VERSION_17
                }
                kotlinOptions {
                    jvmTarget = "17"
                    languageVersion = "1.9" // 与你设置的Kotlin版本对应
                }
            }
        }
    }
}

4. 彻底清理缓存后重建

执行以下命令清除所有缓存并重新构建:

flutter clean
rm -rf android/.gradle
rm -rf ~/.gradle/caches
flutter pub get
flutter run

5. 检查flutter_stripe版本兼容性

确保使用的flutter_stripe版本适配当前Kotlin版本,可尝试升级到最新稳定版:

flutter pub upgrade flutter_stripe

内容的提问来源于stack exchange,提问作者ABDELWAHED ELOUED

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 12:02:32