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

Flutter集成auth0_flutter时Kotlin版本冲突问题求助

解决Flutter中auth0_flutter Android构建依赖冲突问题

遇到的构建错误:

e: Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors

按以下步骤排查解决:

  • 统一项目Kotlin与AGP版本
    打开项目根目录的build.gradle,确保buildscript块中指定统一的版本(版本号可根据auth0_flutter当前兼容版本调整,示例为稳定兼容组合):

    buildscript {
        ext {
            kotlin_version = '1.8.22'
            agp_version = '7.4.2'
        }
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath "com.android.tools.build:gradle:$agp_version"
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
  • 同步app模块配置
    打开android/app/build.gradle,确保plugins块继承根项目的版本配置,不需要手动指定Kotlin版本:

    plugins {
        id "com.android.application"
        id "kotlin-android"
        id "dev.flutter.flutter-gradle-plugin"
    }
    
  • 强制统一依赖版本(针对顽固冲突)
    在app模块的build.gradle的android块中添加配置,强制所有依赖使用指定的Kotlin版本:

    android {
        // 保留原有配置,新增以下内容
        configurations.all {
            resolutionStrategy {
                force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
                force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
                force "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
            }
        }
    }
    
  • 清理缓存重新构建
    执行以下命令彻底清理缓存并重新构建:

    flutter clean
    flutter pub get
    cd android && ./gradlew clean build --refresh-dependencies
    cd .. && flutter run
    
  • 临时应急方案(不推荐长期使用)
    若以上方法都无效,可在app模块的build.gradle中添加跳过元数据检查的参数,但这只是临时规避,建议后续仍需解决版本冲突:

    android {
        // 保留原有配置,新增以下内容
        kotlinOptions {
            jvmTarget = '1.8'
            freeCompilerArgs += ['-Xskip-metadata-version-check']
        }
    }
    

内容的提问来源于stack exchange,提问作者Farooq Zahid

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 04:30:05