首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計綜合問答

Android Studio 構建失敗:Multiple dex files define BuildConfig 衝突解決

     編輯:程式設計綜合問答

錯誤日誌

com.android.dex.DexException: Multiple dex files define Lcom/handmark/pulltorefresh/library/BuildConfig;
Execution failed for task ':centralAsia:dexDebug'.

根因

同一庫 pulltorefresh 以兩種形式被引入:

  1. 作為 Module 依賴 :pullToRefresh_library
  2. 作為 JAR/AAR 放在 libs/ 或 Maven 依賴

編譯時生成兩份 BuildConfig.class,DEX 合併衝突。

解決方案

方案一:移除重複依賴 (推薦)

// build.gradle (app/module)
dependencies {
    implementation project(':pullToRefresh_library')
    // 刪除這行:implementation files('libs/pulltorefresh.jar')
    // 或刪除:implementation 'com.handmark:pulltorefresh:xxx'
}

方案二:啟用 MultiDex (若確需多庫)

// build.gradle
android {
    defaultConfig {
        multiDexEnabled true
    }
}
dependencies {
    implementation 'androidx.multidex:multidex:2.0.1'
}

// Application 類
public class MyApp extends MultiDexApplication { }

方案三:排除特定類 (治標)

android {
    packagingOptions {
        exclude 'com/handmark/pulltorefresh/library/BuildConfig.class'
    }
}

其他檢查項

  • compileSdkVersion / targetSdkVersion 與支持庫版本匹配
  • JDK 版本:建議 JDK 8/11,避免 JDK 9+ 模塊化導致工具鏈問題
  • Gradle 版本與 Android Gradle Plugin 版本對應表
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved