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

修改Gradle及插件版本后构建失败,求解决方案(Kotlin 1.5.31)

解决Gradle版本与插件版本不兼容导致的构建错误

结合你使用的Kotlin 1.5.31,针对修改Gradle版本和插件后出现的构建错误,可按以下步骤排查解决:

  • 严格匹配版本适配关系
    Kotlin 1.5.31对应的Android Gradle Plugin(AGP)建议版本为7.0.x7.2.x,对应Gradle版本为7.07.3。你可以直接修改项目配置:

    1. 根目录build.gradle(或build.gradle.kts)中的插件依赖:
    dependencies {
        classpath "com.android.tools.build:gradle:7.2.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
    }
    
    1. gradle/wrapper/gradle-wrapper.properties中的Gradle分发版本:
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
    
  • 清理缓存并重新构建
    执行命令清除旧缓存,避免缓存导致的异常:

    # macOS/Linux
    ./gradlew clean build --refresh-dependencies
    
    # Windows
    gradlew clean build --refresh-dependencies
    
  • 统一模块级Kotlin配置
    确保所有模块的build.gradle中Kotlin版本与根目录一致,同时配置JVM目标兼容:

    android {
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        kotlinOptions {
            jvmTarget = '1.8'
        }
    }
    
    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.31"
    }
    
  • 排查并解决依赖冲突
    执行./gradlew dependencies查看项目依赖树,若发现Kotlin相关依赖版本不一致,可通过exclude排除冲突依赖:

    implementation("第三方依赖库:版本号") {
        exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib'
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 06:22:39