Android: Getting "Manifest merger failed" error after updating to a new version of gradle
After accepting to update the project to new version of gradle I get this error:
Error:Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(26.0.0-alpha1) from [com.android.support:cardview-v7:26.0.0-alpha1] AndroidManifest.xml:24:9-38
is also present at [com.android.support:design:25.3.1] AndroidManifest.xml:27:9-31 value=(25.3.1).
Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:22:5-24:41 to override.
How can I solve this problem?
This is my app's build.gradle
file:
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.sample.bookReader"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
...
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:multidex:+'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:cardview-v7:26.0.0-alpha1'
compile 'com.android.support:design:25+'
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
...
}
And this is the project's build.gradle
:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
allprojects {
repositories {
jcenter()
maven { url "https://www.jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
How do I fix this error while maintaining the changes made by updating the gradle version?
Solution 1:
Put this at the end of your app module build.gradle:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '25.3.0'
}
}
}
}
Credit to Eugen Pechanec
Solution 2:
You are using multiple versions of the Android Support Libraries:
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:cardview-v7:26.0.0-alpha1'
compile 'com.android.support:design:25+'
Two are 26.0.0-alpha1
, and one is using 25+
.
Pick one concrete version and use it for all three of these. Since your compileSdkVersion
is not O
, use 25.3.1
for all three of these libraries, resulting in:
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
Solution 3:
I changed all support library versions to 25.3.1 and worked like a charm:
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
You also need to change compileSdkVersion and targetSdkVersion to 25:
compileSdkVersion 25
targetSdkVersion 25
Solution 4:
You can find out what library depends on a wrong version of the support library and exclude it like this:
compile ('com.stripe:stripe-android:5.1.1') {
exclude group: 'com.android.support'
}
stripe-android
in my case.
Solution 5:
I'm not using different versions of libraries and got the same error, it's happened after remove buildToolsVersion
in AS RC 1, but adding tools:node="replace"
did the trick, just add this into your manifest.xml inside <application ..../>
block:
<meta-data
tools:node="replace"
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />