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

Android新手求助:解决transformClassesWithMultidexlistForDebug任务执行失败问题

Fixing the ':app:transformClassesWithMultidexlistForDebug' Error with Duplicate Gson Entries

Hey there! I’ve seen this exact issue pop up a lot with Android multi-dex setups—let’s get you sorted out quickly. The error tells us there are duplicate Gson class entries in your project, which confuses the multi-dex tool when it tries to package everything up.

Here’s how to fix it step by step:

  • First, track down where the duplicate Gson is coming from
    Run this command in your project root (use gradlew.bat if you’re on Windows) to generate your full dependency tree:

    ./gradlew app:dependencies
    

    Search the output for com.google.code.gson—you’ll probably spot multiple versions or third-party dependencies pulling in Gson without you noticing.

  • Exclude duplicate Gson instances from specific dependencies
    If you find a library (say, com.some.thirdparty:library:2.0) that’s bringing in its own version of Gson, add an exclusion rule in your app’s build.gradle file:

    implementation('com.some.thirdparty:library:2.0') {
        exclude group: 'com.google.code.gson', module: 'gson'
    }
    

    Repeat this for every dependency that’s adding an extra Gson copy.

  • Force a single Gson version across your entire project
    To guarantee all dependencies use the same Gson version, add this resolution strategy to your app’s build.gradle (inside the android block, or in the root build.gradle under allprojects):

    configurations.all {
        resolutionStrategy.force 'com.google.code.gson:gson:2.8.0'
    }
    
  • Clean your project and rebuild
    Sometimes old cached files leave behind leftover duplicates. Run:

    ./gradlew clean
    

    Then try building your project again.

Why this happens

Multi-dex requires each class to exist only once in the final package. When multiple dependencies include Gson (even different versions), their jar files end up having duplicate class entries (like the com.google.gson.annotations classes mentioned in your error). The multi-dex tool can’t resolve this automatically, so we have to manually tidy up the dependencies.

内容的提问来源于stack exchange,提问作者s.vijay

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 12:22:53