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

使用Heyzap Mediation集成第三方SDK时遇Gradle构建失败求助

Fixing Gradle Dex Merge Error with Heyzap Mediation in Unity 2018.3.11

This is a super common dependency conflict issue—here's how to fix it step by step:

Root Cause

The error Program type already present: android.support.v4.app.INotificationSideChannel happens because Heyzap Mediation already includes a version of the Android Support Library, and the third-party SDK you're adding is pulling in a different (or duplicate) version of the same library. Gradle can't merge these duplicate classes into your Dex archive, hence the failure.

Solutions

1. Force a Unified Support Library Version

This is the quickest fix for most cases:

  • Open your Unity project, go to Player Settings > Publishing Settings, check the box for Custom Gradle Template (this generates Assets/Plugins/Android/mainTemplate.gradle).
  • Open the generated mainTemplate.gradle file, and add this configuration inside the android block (or right before the dependencies block):
    configurations.all {
        // Force the same version of support-v4 across all dependencies
        resolutionStrategy.force 'com.android.support:support-v4:28.0.0'
        // You can add other support libraries here if needed, e.g., appcompat-v7
        resolutionStrategy.force 'com.android.support:appcompat-v7:28.0.0'
    }
    
    Unity 2018.3 uses Support Library 28.0.0 by default, so this version should be compatible with Heyzap and most third-party SDKs.

2. Exclude Duplicate Dependencies from Specific SDKs

If you know exactly which third-party SDK is causing the conflict, you can explicitly exclude the conflicting support library from its dependency:

  • In the dependencies block of mainTemplate.gradle, modify the SDK's implementation line to exclude the support-v4 module. For example, if it's AdMob:
    implementation ('com.google.android.gms:play-services-ads:18.3.0') {
        exclude group: 'com.android.support', module: 'support-v4'
    }
    
    Use this if the forced version approach causes issues with the third-party SDK.

3. Enable Multidex (If Needed)

Sometimes the conflict is compounded by having too many methods in your build. Enable Multidex to resolve this:

  • In Player Settings > Other Settings, set Minimum API Level to 21 or higher (Android 5.0+).
  • If you need to support lower API levels, add this to mainTemplate.gradle:
    android {
        defaultConfig {
            multiDexEnabled true
        }
    }
    dependencies {
        implementation 'com.android.support:multidex:1.0.3'
    }
    
  • If you have a custom Application class, make it extend MultiDexApplication; otherwise, add MultiDex.install(this) to the onCreate method of your default application.

4. Clean Build Cache

Old cache files can cause unexpected issues, so do a full clean before rebuilding:

  • Close Unity.
  • Delete the Library, Temp, and Android Build folders from your project directory.
  • Reopen Unity and try building again.

Additional Notes

  • Make sure you're using the latest compatible version of Heyzap Mediation—older versions might have outdated dependency references.
  • Check the documentation of your third-party SDK to confirm their recommended Support Library version, and align it with Unity's default if possible.

内容的提问来源于stack exchange,提问作者Muhammad Ahmad Saleem

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 07:11:48