React Native集成OneSignal后构建失败:依赖冲突求助
Hey there, let's tackle this manifest merger error you're facing after adding OneSignal to your React Native project. The issue boils down to conflicting versions of Android Support Library dependencies—your project has com.android.support:cardview-v7:26.0.1 and OneSignal is pulling in com.android.support:support-v4:26.1.0, which causes the manifest merger to throw a fit when it sees two different values for the android.support.VERSION meta-data.
Here are two reliable ways to fix this:
Option 1: Override the Version in AndroidManifest.xml
This directly follows the error message's suggestion:
- First, make sure your root
<manifest>tag includes thetoolsnamespace. If it doesn't, add it:<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.your.app.package"> - Next, inside the
<application>tag, add (or modify if it already exists) themeta-dataentry forandroid.support.VERSION, using thetools:replaceattribute to force the correct version:
Use the higher version (26.1.0) here since it's the one OneSignal relies on, which should be backward-compatible with your existing code.<application ...> <!-- Your existing app components go here --> <meta-data android:name="android.support.VERSION" android:value="26.1.0" tools:replace="android:value" /> </application>
Option 2: Force a Unified Support Library Version (Recommended)
This prevents similar conflicts from popping up in the future by forcing all Android Support Library dependencies to use the same version:
- Open your app-level
build.gradlefile (located atandroid/app/build.gradle) - Add this block outside the
android { ... }section:
This tells Gradle to use version 26.1.0 for every Support Library dependency, eliminating version mismatches entirely.configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> def requested = details.requested if (requested.group == 'com.android.support') { if (!requested.name.startsWith('multidex')) { details.useVersion '26.1.0' } } } }
After making either change, clean and rebuild your project—this should resolve the manifest merger error and let you build your app with OneSignal integrated.
内容的提问来源于stack exchange,提问作者Mizlul

