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

集成Facebook Audience Network SDK时出现Unable to merge dex错误

Fixing Dex Merge Error When Integrating Facebook Audience Network SDK

Hey, I’ve run into this exact dex merge issue before when working with third-party SDKs like Facebook Audience Network—let’s break down the fixes step by step based on your Gradle config:

1. Remove Duplicate Google Play Services Dependencies

Your biggest red flag here is that you’re including the full play-services package and individual Play Services modules (like play-services-base, play-services-ads, play-services-auth). The full play-services library already contains all these individual modules, so having both creates duplicate class definitions that trigger the dex merge error.

Fix: Delete this line from your app-level dependencies block:

implementation 'com.google.android.gms:play-services:11.8.0'

Keep only the individual Play Services modules your app actually uses (you already have the necessary ones listed: base, ads, auth, firebase-messaging).

2. Align Facebook Audience Network SDK with Your Google Play Services Version

Your FAN SDK version (4.27.0) is quite outdated, and it likely depends on an older version of Google Play Services—this creates a version conflict with your 11.8.0 Play Services setup.

Fix: Update the FAN SDK to a version compatible with Play Services 11.8.0. For example:

implementation 'com.facebook.android:audience-network-sdk:5.10.0'

(Pro tip: If you can afford to update, moving to more recent stable versions of both Play Services and FAN SDK will help avoid future compatibility headaches.)

3. Clean & Rebuild Your Project

After adjusting dependencies, these steps are critical to clear cached build files that might still hold conflicting data:

  • Go to Build > Clean Project in Android Studio
  • Then run Build > Rebuild Project
  • If that still fails, delete the .gradle folder in your project root, plus the build folders in both your app and project directories, then rebuild from scratch.

4. Double-Check Multidex Setup

You already have multiDexEnabled true in your defaultConfig, but make sure your app properly initializes Multidex:

  • If you don’t have a custom Application class, update your AndroidManifest.xml to use MultiDexApplication:
    <application
        android:name="android.support.multidex.MultiDexApplication"
        ...>
        <!-- Your other app config -->
    </application>
    
  • If you do have a custom Application class, override attachBaseContext to initialize Multidex:
    public class MyApp extends Application {
        @Override
        protected void attachBaseContext(Context base) {
            super.attachBaseContext(base);
            MultiDex.install(this);
        }
    }
    

Quick Extra Check

You’re already doing this well, but just confirm all your support libraries (appcompat-v7, design, recyclerview-v7, etc.) are using the same version (27.0.2 in your case)—mixed support library versions are another common cause of dex errors.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:51:17