54

I updated today my support repository to 46.0.0 as the Android Studio notification popped up.

I go the error below :

Error:Execution failed for task ':app:processDevDebugManifest'.

Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(25.3.0) from [com.android.support:support-v13:25.3.0] AndroidManifest.xml:27:9-31 is also present at [com.android.support:preference-v7:26.0.0-alpha1] AndroidManifest.xml:24:9-38 value=(26.0.0-alpha1). Suggestion: add 'tools:replace="android:value"' to element at AndroidManifest.xml:25:5-27:34 to override.

I updated all my dependencies to use Revision 26.0.0 Alpha 1 from 25.3.0, but it turns out I need to bump the compileSdk from 25 to 26. You can't do that if you have AS 2.3, you need to get the unstable alpha/beta version from canary.

This link shows the changes: https://developer.android.com/topic/libraries/support-library/revisions.html#26-0-0-alpha1

And concerning migrating to the new android O, that's the link: https://developer.android.com/preview/migration.html

It seems using AS stable version will not work with new repository.

How can I go back to the Android Studio Repository Version 45 instead of the new 46?

** Update: The merged manifest shows one of the generated library manifest contains

<meta-data
        android:name="android.support.VERSION"
        android:value="26.0.0-alpha1" />

But since it's a generated file editing is useless, that's why for now I'd stick to rev 45 until the new AS is in stable build

usernotnull
  • 3,480
  • 4
  • 25
  • 40
  • Here check out my answer for android 'O' `gradle` configuration. http://stackoverflow.com/questions/42949170/errorexecution-failed-for-task-appprocessdebugresources-when-using-font-fol/42949957?noredirect=1#comment72995493_42949957 – Paresh P. Mar 22 '17 at 11:26
  • @Wizard It doesn't work on AS 2.3 because I can't download the latest platform: Error:Failed to find target with hash string 'android-O' in: **\AppData\Local\Android\sdk Install missing platform(s) and sync project – usernotnull Mar 22 '17 at 11:34
  • Alright - switch your channel to canary. – Paresh P. Mar 22 '17 at 11:45
  • That's the obvious answer, but some companies like to work on stable builds. Shoving an update which breaks the platform we work on was a very bad move, especially when we have a product that we don't want to move to version O because it's released. Time for a re-install of old AS version I guess – usernotnull Mar 22 '17 at 11:55
  • Woo..wait! Android `O` is not released yet. The released version is `O preview`. Have you read the footnotes in my answer? – Paresh P. Mar 22 '17 at 11:57
  • yes, as it's also written on the official link. I just didn't want anything to do with version O and I want to bring AS back to the way it was by having support version 45, but I guess that's not reversible after the update, just gotta re-install older version – usernotnull Mar 22 '17 at 12:21
  • Oh yeah! You are gonna need re-installation. – Paresh P. Mar 22 '17 at 12:22

7 Answers7

166

What's the problem

Some libraries depend on version "X or newer" of Android support libraries so Gradle dependency resolution grabs whatever is the newest available ignoring you actually have a precise version specified in your dependencies block.

This is not what you want. You want all support libraries with same version and major version has to match compile SDK version.

What's the solution

Fortunately you can force a specific support library version.

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') {
            // Skip multidex because it follows a different versioning pattern.
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.0'
            }
        }
    }
}

Of course replace the version with whatever it is you're using.

Version values for support libraries in dependecies block are now irrelevant.

If you have doubts

This is a well documented method and it's working.

What can you do to help

Find the libraries which depend on a range of support library versions

gradlew dependencies --configuration compile -p <module name> | grep ,

and let the authors of said libraries know they should transitively depend on the oldest support libs their library can do with.

This aims to avoid the issue altogether.

Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124
  • 5
    In build.gradle, Android "cannot resolve symbol" for DependencyResolveDetails. Only happens in Android Studio 2.3.2, Gradle version 3.3, Gradle plugin 2.3.2. Any ideas? – Baker Apr 28 '17 at 00:29
  • 4
    @Baker Remove `DependencyResolveDetails` and try again. Groovy (the language) is dynamically typed so the type declaration is not needed. – Eugen Pechanec Apr 28 '17 at 07:33
  • So many obscure "resource not found"-esque errors that had no Google search results... and it all came down to mixing and matching of Android support library version differences. How many hours I wasted trying to figure this shit out... if I could +1000 your answer I would! – Chris Cirefice Jan 22 '18 at 21:26
  • Can you explain why you skip multidex lib? What are the dangers of forcing multidex to a specific version? – tir38 Apr 07 '18 at 18:26
  • @tir38 No, no, there's no danger, it's just that Multidex follows a different versioning pattern. There's no Multidex 25.3.0 and so on, got it? – Eugen Pechanec Apr 07 '18 at 21:43
  • Version of what ? com.android.support:appcompat ? – Saeed Halawani Feb 25 '19 at 08:44
  • @Androider What version of what? Quote the confusing part, now I don't know which bit you refer to. – Eugen Pechanec Feb 25 '19 at 09:48
  • @ Eugen Pechanec configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> def requested = details.requested if (requested.group == 'com.android.support') { // Skip multidex because it follows a different versioning pattern. if (!requested.name.startsWith("multidex")) { details.useVersion '25.3.0' // i mean this : this is the version of ?? } } } } – Saeed Halawani Feb 27 '19 at 09:38
  • @Androider Version of everything under `com.android.support`, AppCompat, support-v4, whatever. All support libraries until 28.0.0 must have the same version. This piece of code does that. – Eugen Pechanec Feb 27 '19 at 09:53
  • @EugenPechanec unfortunately after adding these line i've got this error the app crash on start : No static method isDeviceProtectedStorage(Landroid/content/Context;)Z in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' << did you face this problem ?? – Saeed Halawani Feb 27 '19 at 13:15
  • @Androider Some other library depends on newer version of support library than you specified, [example here](https://stackoverflow.com/questions/43653431). The answer is almost 2 years old, put a recent version of support library after `useVersion`. The last is `28.0.0` https://developer.android.com/topic/libraries/support-library/revisions – Eugen Pechanec Feb 27 '19 at 13:22
3

Step 1

To escape Gradle checking for incompatible com.android.support versions a quick fix is to add following code in app module build.gradle.

dependencies {
    //noinspection GradleCompatible
}

This is a temporary fix that doesn't solve the underlying problems! It helped to continue develop your app with minimal modifications.

Step 2

Add this to the main manifest file AndroidManifest.xml.

<meta-data
    tools:replace="android:value"
    android:name="android.support.VERSION"
    android:value="25.3.1" />

This entry will be removed when one of the next updates of the support repository is available.

Step 3

Add the following code at the end of app module build.gradle file:

configurations.all {
    resolutionStrategy.eachDependency { details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.1'
            }
        }
    }
}

NB: It is recommended to make sure your Gradle libraries are updated and compatible to avoid runtime errors.

Hamza Rashid
  • 1,329
  • 15
  • 22
  • 3
    Step 3 makes Step 2 obsolete. Step 1 only affects IDE hints and does nothing for compilation. Which leaves us with the core of my own answer, c'mon, man... – Eugen Pechanec Jul 20 '17 at 22:35
2

Their is a solution to fix it out:

  1. Move to Project explorer view
  2. Reach to bottom their is External Libraries
  3. See which library is using 26.0.0-alpha6
  4. Now write this in app.gradle on the basis of library in Step 3

Ex. in my case:

configurations.all {
    resolutionStrategy.force 'com.android.support:appcompat-v7:25.3.0'
    resolutionStrategy.force 'com.android.support:support-v13:25.3.0'
}

This will force project to use mentioned library.

Rajesh Tiwari
  • 410
  • 5
  • 22
  • Let's say one other library depends on `support-v4:[24.0.0,)`. Will forcing appcompat-v7 to a particular version also force the same version of support-v4 because appcompat-v7 depends on it? Or do I have to specify each artifact separately (which is going to be a pain in the ass considering support-v4 split to several artifacts)? – Eugen Pechanec Mar 24 '17 at 19:02
  • @EugenPechanec , lint always generate the warning you must use the same dependencies to avoid runtime conflict/error so its temporary solution to fix out the issue. – Rajesh Tiwari Mar 25 '17 at 04:47
  • 1
    @RajeshTiwairi The error is produced by manifest merger. Lint is a tool that checks android source and resources. This is not about Lint, my question is about Gradle. – Eugen Pechanec Mar 25 '17 at 10:03
1

I think the best solution is to just revert the Android Support Library to version 45.

To do this, open this link (change version to whatever suits your needs)

https://dl-ssl.google.com/android/repository/android_m2repository_r45.zip

When downloaded, unzip and copy m2repository to android-sdk-root-folder\extras\android. Make sure to delete the existing m2repository prior to unzipping to avoid problems.

Zoran P
  • 336
  • 1
  • 9
0

This is a temporary fix that doesn't solve the underlying problems! It helped me continuing developing software with minimal modifications. Just add this to the main manifest:

<meta-data
    tools:replace="android:value"
    android:name="android.support.VERSION"
    android:value="25.3.0" />

This entry can hopefully be removed again with one of the next updates of the support repository.

SOLUTION: The marked solution worked for me by adding the following to 4 of my 10 build.gradle files:

configurations.all {
    resolutionStrategy.eachDependency { details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.0'
            }
        }
    }
}
Ludger
  • 19
  • 1
  • 1
    Doesn't change the fact that the support library version 26 was imported. You're just masking the problem and it is going to bite you in the end. – Eugen Pechanec Mar 22 '17 at 16:22
  • @EugenPechanec Your solution doesn't work for me: Cannot resolve symbol 'DependencyResolveDetails'. What am I missing? – Ludger Mar 27 '17 at 12:33
  • why don't you comment on my answer if you have problem with my answer? Groovy (the language build.gradle is written in) is dynamically typed. Remove "DependencyResolveDetails" and try again. If that doesn't work leave another comment. – Eugen Pechanec Mar 27 '17 at 13:24
  • @EugenPechanec I'm a new user and I don't have enough reputations (probably below 0 now) to comment on your answer. Your suggestion doesn't work for me. I get the same error message as without. I temporarily stick to my fix. Don't have time for a reinstallation right now. Still can't understand the downvote. Maybe I didn't describe my motivation behind the fix exactly enough. – Ludger Mar 27 '17 at 21:28
  • I see, so here's the thing: Your "fix" doesn't fix anything. You import some parts of support library v25.3.0 and some parts v26.0.0-alpha1. The error let's you know that there is a conflict. You just shut up the error but the conflict is still there and you may (probably will) get runtime errors. So let's try something else: Use Gradle 3.4.1 (in `gradle/gradle-wrapper.properties`) and Android build plugin 2.3.0 (in root project `build.gradle`) and if that doesn't work, get back to me once more. **Make sure you put the code at the end of your *app module* build.gradle.** – Eugen Pechanec Mar 27 '17 at 21:35
  • @EugenPechanec I know that the fix doesn't solve the underlying problems. That's part of the definition of a quick/temporary fix, at least to my understanding. It helped me tremendously to continue developing software without wasting my time and making my client pay for that. Whatever, I solved the problem by copying your solution (except for the DependencyResolverDetails) to 4 of my 10 modules 'build.gradle'. The singular 'module' confused me a bit at the first attempt. I don't like this solution at all, but don't have time to look for anything else. Thanks for your help! – Ludger Mar 28 '17 at 01:32
-1

just do this that's all :-

compile 'com.android.support:appcompat-v7:25.3.1'

here v7:25.3.1 is my current version you just put urs.

in app gradle file

-1

to me the problem was that the versions weren't the same in here

implementation 'com.android.support:appcompat-v7:**26.0.0-beta1**'
implementation 'com.android.support:support-v4:**26.0.0-beta1**'
implementation 'com.android.support:design:**26.0.0-beta1**'

and the card view was

compile 'com.android.support:cardview-v7:26.1.0'

so i changed the version libraries to..

implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:design:26.1.0'

hope this help, good luck