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

Android Studio Gradle同步成功但Debug构建dexBuilderDebug报错

故障定位

构建卡在Task :app:dexBuilderDebug阶段失败,由4处配置错误导致:

  • 模块级依赖中错误引入了Gradle构建插件包,该包仅需在项目级buildscript的classpath中声明,作为应用运行时依赖打入会触发dex打包冲突
  • 启用了已废弃的kotlin-android-extensions插件,该插件在Kotlin 1.6+版本已被正式移除,与当前使用的AGP 7.2.1版本不兼容
  • Glide、ButterKnife依赖版本过旧,与compileSdk 32、Java 1.8的编译配置存在字节码兼容问题
  • 开启了multiDex配置但未引入对应multidex依赖,dex拆分逻辑无法正常执行
错误参考

报错截图

修正方案

1. 替换项目根目录下build.gradle内容

移除重复声明的插件块,保持版本声明统一:

buildscript {
    ext.kotlin_version = '1.6.21'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.android.tools.build:gradle:7.2.1'
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

2. 替换app模块目录下build.gradle内容

移除错误依赖、废弃插件,升级兼容版本,补充缺失依赖:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.google.gms.google-services'
}

android {
    compileSdk 32
    buildFeatures {
        viewBinding = true
    }
    defaultConfig {
        applicationId "com.example.progetto_tpsi"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.google.firebase:firebase-database:20.0.5'
    // 补充multidex必需依赖
    implementation 'androidx.multidex:multidex:2.0.1'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    // 升级Glide到兼容AGP7的版本,移除错误引入的gradle插件依赖
    implementation 'com.github.bumptech.glide:glide:4.13.2'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'

    implementation 'org.greenrobot:eventbus:3.3.1'

    // 升级ButterKnife到兼容版本
    implementation 'com.jakewharton:butterknife:10.2.3'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
}

注:如果之前代码里用了kotlin-android-extensions的视图绑定功能,直接删除对应导入语句即可,当前项目已开启viewBinding,可完全替代该插件的视图绑定能力。

3. settings.gradle保持原有内容无需修改

4. 清理缓存重新构建

配置替换完成后,依次点击Android Studio顶部菜单栏的 Build > Clean Project,等待清理完成后执行 Build > Rebuild Project,构建完成后即可正常运行、调试项目。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.03 04:18:31