React Native(分离版)安装OneSignal后Android Studio编译失败:清单合并错误
Hey there, let's get this annoying manifest merge error sorted out for your React Native (detached) app with OneSignal. This is a super common Android support library version clash, and here's how to fix it step by step:
Understanding the Problem
The error boils down to conflicting support library versions:
Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(26.0.2) from [com.android.support:appcompat-v7:26.0.2] AndroidManifest.xml:28:13-35 is also present at [com.android.support:exifinterface:26.0.1] AndroidManifest.xml:25:13-35 value=(26.0.1). Suggestion: add 'tools:replace="android:val...
In short, OneSignal is pulling in an older exifinterface library, which clashes with the newer appcompat-v7 version your project uses. The Android manifest merger can't decide which version to use, so it throws this error.
Solution 1: Force a Unified Support Library Version
This is my go-to fix for these conflicts—we'll tell Gradle to use the same version for all support library dependencies:
- Open the root-level
build.gradlefile of your Android project (not the one inside theappmodule). - Add the following
configurationsblock inside theallprojectssection:allprojects { repositories { // ... keep your existing repository entries here } configurations.all { resolutionStrategy { // Force exifinterface to match your appcompat-v7 version (26.0.2 here) force 'com.android.support:exifinterface:26.0.2' // If you upgrade your support library version later, update this number too } } }
Solution 2: Use tools:replace to Override the Conflict
If you want to follow the error message's direct suggestion, here's how to implement it:
- First, make sure your
AndroidManifest.xmlincludes thetoolsnamespace at the top:<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.your_app_package_name"> - Inside the
<application>tag, add a meta-data entry to explicitly set the version and override conflicting declarations:<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme"> <!-- Add this to resolve the version conflict --> <meta-data android:name="android.support.VERSION" android:value="26.0.2" tools:replace="android:value" /> <!-- Rest of your application content (activities, services, etc.) --> </application>
Final Step: Clean & Rebuild
After applying either fix, clear old build artifacts and rebuild to make sure changes take effect:
- In Android Studio: Go to
Build > Clean Project, thenBuild > Rebuild Project. - Or via terminal:
./gradlew clean ./gradlew assembleDebug
That should resolve the manifest merge error and let you compile your app with OneSignal integrated smoothly!
内容的提问来源于stack exchange,提问作者Mizlul

