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

升级Android Support库至28.0.0遇Multiple Dex错误求助

Fixing Multiple Dex Error for ListenableFuture After Upgrading to Support Library 28.0.0

Hey there! Let's get this multiple dex issue sorted out for you. The error you're seeing—Multiple dex files define Lcom/google/common/util/concurrent/ListenableFuture;—happens because the ListenableFuture class is being pulled in by multiple dependencies in your project. Specifically, your Android Support Library 28.0.0, Firebase/Play Services dependencies, and possibly your Architecture Components (like Lifecycle or Room) all include versions of this class, causing a conflict.

Here are the step-by-step fixes to resolve this:

1. Force a Conflict-Avoiding Version of ListenableFuture

Google provides a special "empty" version of the listenablefuture artifact that eliminates conflicts, since the Support Library already includes a compatible implementation. Add this to your app-level build.gradle, outside the android block:

configurations.all {
    resolutionStrategy {
        force 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
    }
}

2. Verify Multidex Setup (If Needed)

Even though you have multiDexEnabled true and updated the multidex dependency, double-check your Application class:

  • If you use a custom Application class, make sure it extends MultiDexApplication:
    public class MyApp extends MultiDexApplication {
        // Your existing code here
    }
    
  • If you can't extend MultiDexApplication (e.g., you're using another base class), add this method to your Application class:
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
    

Don't forget to update your AndroidManifest.xml to reference this custom Application class if you haven't already.

3. Clean and Rebuild Your Project

After making these changes, run these commands to ensure old build artifacts are cleared:

# For macOS/Linux
./gradlew clean

# For Windows
gradlew clean

Then re-sync your Gradle project and try running the app again.

4. (Optional) Identify and Exclude Specific Conflicting Dependencies

If the above fix doesn't work, you can pinpoint exactly which dependencies are bringing in the duplicate ListenableFuture by running:

./gradlew app:dependencies

Search the output for com.google.guava:guava or ListenableFuture to find the conflicting sources. Then exclude the Guava dependency from those modules. For example, if android.arch.lifecycle:extensions is the culprit, modify its dependency line like this:

implementation ('android.arch.lifecycle:extensions:1.0.0') {
    exclude group: 'com.google.guava', module: 'guava'
}

Repeat this for any other dependencies that show up as conflicting sources.

Final Notes

Also, consider updating your Gradle plugin version from 3.0.1 to a newer version (like 3.2.1 or later) in your project-level build.gradle—this can help with dependency resolution and avoid similar conflicts in the future:

classpath 'com.android.tools.build:gradle:3.2.1'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 09:13:28