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

测试Android应用时遇多DEX文件定义冲突错误,求解决方法

Fixing "Multiple dex files define Lcom/android/vending/billing/IInAppBillingService;" Error

Hey there, let's get this dex conflict sorted out for you! That error pops up when two or more dependencies in your project define the exact same class—in this case, IInAppBillingService from Google's Play Billing system.

Looking at your build.gradle dependencies, here's what's causing the problem:

  • You've added com.android.billingclient:billing:1.0 twice (duplicate dependency)
  • You're also using com.anjlab.android.iab.v3:library:1.0.44, a third-party In-App Billing library that includes its own copy of the IInAppBillingService class—this clashes directly with the official Google Billing Client library.

Solution: Pick One Billing Library & Clean Up Dependencies

You can't use both the official Google Billing Client and the third-party ANJLab IAB library together. Choose one, and remove the other. Also, clean up any duplicate dependencies.

Option 1: Use Official Google Billing Client (Recommended)

Remove the third-party IAB library and the duplicate billingclient entry. Here's your cleaned-up dependencies block:

dependencies {
    api fileTree(include: ['*.jar'], dir: 'libs')
    api 'com.android.billingclient:billing:1.0'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //noinspection GradleCompatible,GradleCompatible
    api 'com.android.support:appcompat-v7:27.0.2'
    api 'com.google.android.gms:play-services-ads:11.8.0'
    api 'com.android.support:design:27.0.2'
    api 'com.android.support.constraint:constraint-layout:1.0.2'
    api 'com.android.support:support-v4:27.0.2'
    testCompile 'junit:junit:4.12'
    api 'com.android.support:gridlayout-v7:27.0.2'
}

Option 2: Stick with the Third-Party ANJLab IAB Library

If you need to keep using the ANJLab library, remove both instances of the official billingclient dependency:

dependencies {
    api fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //noinspection GradleCompatible,GradleCompatible
    api 'com.android.support:appcompat-v7:27.0.2'
    api 'com.google.android.gms:play-services-ads:11.8.0'
    api 'com.android.support:design:27.0.2'
    api 'com.android.support.constraint:constraint-layout:1.0.2'
    api 'com.anjlab.android.iab.v3:library:1.0.44'
    api 'com.android.support:support-v4:27.0.2'
    testCompile 'junit:junit:4.12'
    api 'com.android.support:gridlayout-v7:27.0.2'
}

Extra Tip

I noticed you also have duplicate com.android.support:support-v4:27.0.2 entries—cleaning those up (like I did in the examples above) helps keep your dependency tree tidy and avoids potential future issues.

After making these changes, run Clean Project followed by Rebuild Project in Android Studio, and the dex error should be gone!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 03:37:26