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

添加Meta Audience Network后Android项目出现重复类错误

解决添加Meta依赖后Android项目的重复类冲突

问题本质

这些错误是因为项目同时引入了**AndroidX核心库(androidx.core:core:1.9.0)**和旧版Support兼容库(com.android.support:support-compat:25.2.0),两者包含完全相同的类定义,导致构建时冲突。

解决方案

1. 启用Jetifier自动迁移(推荐)

Android Studio的Jetifier工具可自动将第三方库中的旧Support依赖转换为AndroidX版本,无需手动修改:

  • 打开项目根目录的gradle.properties,确保添加以下配置:
    android.useAndroidX=true
    android.enableJetifier=true
    
  • 同步Gradle后,Jetifier会自动处理Meta依赖中的旧Support库引用。

2. 手动排除Meta依赖中的Support库

如果Jetifier未生效,可在引入Meta依赖时直接排除冲突模块:
假设你的Meta依赖是com.facebook.android:facebook-android-sdk:x.x.x,修改Module级build.gradle中的依赖声明:

implementation('com.facebook.android:facebook-android-sdk:x.x.x') {
    exclude group: 'com.android.support', module: 'support-compat'
}

替换为你实际使用的Meta SDK坐标即可。

3. 定位冲突来源

若不确定哪个依赖引入了旧版support-compat,执行以下Gradle命令查看完整依赖树:

./gradlew app:dependencies

搜索com.android.support:support-compat:25.2.0找到依赖路径,再针对性处理。

原始错误信息

Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.2.0-runtime (com.android.support:support-compat:25.2.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.2.0-runtime (com.android.support:support-compat:25.2.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.2.0-runtime (com.android.support:support-compat:25.2.0)
Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.2.0-runtime (com.android.support:support-compat:25.2.0)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.2.0-runtime (com.android.support:support-compat:25.2.0)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.2.0-runtime (com.android.support:support-compat:25.2.0)
Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.2.0-runtime (com.android.support:support-compat:25.2.0)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.2.0-runtime (com.android.support:support-compat:25.2.0)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.2.0-runtime (com.android.support:support-compat:25.2.0)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.9.0-runtime (androidx.core:core:1.9.0) and support-compat-25.2.0-runtime (com.android.support:support-compat:25.2.0)
提示:请查看文档了解如何修复依赖解析错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 15:30:50