This entry in my gradle file :
androidTestCompile ('com.squareup.okhttp:mockwebserver:2.7.0')
is throwing error:
Warning:Conflict with dependency 'com.squareup.okio:okio'. Resolved versions for app (1.8.0) and test app (1.6.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
I tried commenting out different compile entries in my gradle file to find out which one was conflicting but I just can't find which one uses com.squareup.okio:okio.
UPDATE:
I was able to get the dependencies by running: gradlew.bat app:dependencies > c:\tmp\output.txt
+--- com.squareup.retrofit2:retrofit:2.0.0 -> 2.1.0
| \--- com.squareup.okhttp3:okhttp:3.3.0
| \--- com.squareup.okio:okio:1.8.0
--- com.squareup.okhttp:mockwebserver:2.7.0
| +--- com.squareup.okhttp:okhttp:2.7.0
| | \--- com.squareup.okio:okio:1.6.0
So as you can see, retrofit 2.0 uses okhttp3 which uses okio:1.8.0. On the other hand mockwebserver:2.7.0 uses okhttp:2.7.0 which uses okio:1.6.0. So how can I resolve this?
Here are the entries in "dependencies" section of my gradle file:
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
//retrofit
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.retrofit2:converter-gson:2.+'
compile 'com.squareup.retrofit2:adapter-rxjava:2.+'
compile 'com.squareup.retrofit2:retrofit-mock:2.+'
//recycler view
compile 'com.android.support:recyclerview-v7:+'
//picasso image caching
compile 'com.squareup.picasso:picasso:2.5.2'
//jackson parser
compile (
[group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.4.1']
)
//Dagger
compile 'com.google.dagger:dagger:2.7'
apt 'com.google.dagger:dagger-compiler:2.7'
//constraint based layouts
compile 'com.android.support:design:24.1.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
//for chrome debugging
compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.facebook.stetho:stetho-okhttp3:1.4.1' //for retrofit
//RxJava
compile 'io.reactivex:rxandroid:1.2.1'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
compile 'io.reactivex:rxjava:1.1.6'
//--- For Testing ---
//robolectric:
testCompile "org.robolectric:robolectric:3.2.2"
//mockito
testCompile "org.mockito:mockito-core:2.+"
testCompile('org.hamcrest:hamcrest-core:1.3')
testCompile('org.hamcrest:hamcrest-library:1.3')
testCompile 'junit:junit:4.12'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
// Espresso-web for WebView support
androidTestCompile( 'com.android.support.test.espresso:espresso-web:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile( 'com.android.support.test:runner:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile( 'com.android.support.test:rules:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile ('org.powermock:powermock-api-mockito:1.6.2') {
exclude module: 'hamcrest-core'
exclude module: 'objenesis'
}
//mockwebserver
//testCompile 'com.squareup.okhttp3:mockwebserver:3.3.0'
androidTestCompile ('com.squareup.okhttp:mockwebserver:2.7.0')
androidTestCompile 'com.squareup.spoon:spoon-client:1.2.0'
I solved by using
Retrofit version 2.3.0 -> com.squareup.retrofit2:retrofit:2.3.0
MockWebServer version 3.8.0 -> com.squareup.okhttp3:mockwebserver:3.8.0
try exclude okio from androidTestCompile
androidTestCompile ('com.squareup.okhttp:mockwebserver:2.7.0') {
exclude module: 'com.squareup.okio'
}
When instrumentation tests are run, both the main APK and test APK share the same classpath. Gradle build will fail if the main APK and the test APK use the same library (e.g. Guava) but in different versions. If gradle didn't catch that, your app could behave differently during tests and during normal run (including crashing in one of the cases).
ref - https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Resolving-conflicts-between-main-and-test-APK
Which means dependencies in each configuration i.e compile, androidTestCompile & testCompile should be of the same versions.
Resolving the conflict
Update parent dependencies(retrofit & mockwebserver) such that they all share the same child dependencies(okhttp & okio) across configurations.
OR
Explicitly add the dependency in the configuration(compile, androidTestCompile or testCompile) that has the least version.
In your case adding androidTestCompile('com.squareup.okio:okio:1.6.0') should resolve the conflict.
Now each androidTest dependency that needs okio will use the latest version.
Note
Whenever there are version conflicts within the same configuration, the latest available version of the dependency is automatically used. This is not the case for version conflicts across configurations, hence the error.
example - Here in my compile configuration okhttp3 dependencies are replaced with the latest version of 3.9.0 whenever there is a conflict.
The dependency versions for these two versions of Retrofit and MockWebServer line up:
com.squareup.retrofit2:retrofit:2.2.0
com.squareup.okhttp3:mockwebserver:3.6.0
Rather than deal with dependency conflicts, I'd recommend using these two versions.
Related
I have been charged with integrating Dagger in our existing project and I am having a bit of a problem with the dagger annotation processor.
My environment is pretty restricted so I cannot just use jcenter() or even Google Maven to get dependencies. We have an internal Ivy repo that stores and manages all of our Dependencies.
That said, I have pulled down all the dependencies that Dagger requires but I still have an issue. Gradle sync finishes successfully and resolves the dependencies, however when I go to build I get the following error.
error: Bad service configuration file, or exception thrown while
constructing Processor object: javax.annotation.processing.Processor:
Provider dagger.internal.codegen.ComponentProcessor could not be
instantiated: java.lang.NoClassDefFoundError:
com/google/common/collect/SetMultimap
Clearly I am missing a dependency as when I specifically specify and allow jcenter() and Google Maven as repositories, which I can do for testing purposes, but for prod building this cannot be allowed, I am able to build with no exceptions.
Now a strict reading of the error tells me that Dagger cannot find com.google.comm.collect.SetMutliMap.
I have searched quite a bit trying to find this dependency and about all I can find is that this file is a part of Guava or at least some of its functions are.
One thing to note is I am using the following version of gradle:
classpath 'com.android.tools.build:gradle:3.0.0'
Here is my dagger dependency in build.gradle which is an older version:
//Dagger
compile 'com.google.dagger:dagger:2.10'
annotationProcessor 'com.google.dagger:dagger-compiler:2.10'
Other dependencies:
//lifecycle libs
compile "android.arch.lifecycle:runtime:1.0.3"
compile "android.arch.lifecycle:extensions:1.0.0"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0"
compile 'de.greenrobot:eventbus:2.4.1'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'commons-io:commons-io:2.4'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.github.ganfra:material-spinner:2.0.0'
compile 'com.nulab-inc:zxcvbn:1.1.3'
compile('com.google.android.gms:play-services-vision:10.2.1') {
exclude group: 'com.android.support'
}
compile 'org.zakariya.stickyheaders:stickyheaders:0.7.6'
compile 'com.google.code.gson:gson:2.8.0'
compile('com.google.android.gms:play-services-gcm:10.2.1') {
exclude group: 'com.android.support'
}
compile('com.google.android.gms:play-services-maps:10.2.1') {
exclude group: 'com.android.support'
}
compile('com.google.android.gms:play-services-location:10.2.1') {
exclude group: 'com.android.support'
}
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:support-annotations:26.1.0'
//retrofit dependencies
compile 'com.squareup.okhttp3:okhttp:3.9.0'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.9.0'
Due to my restricted environment, I cannot update dependencies as I would like to do, so working within what I have, does anyone have any ideas on how to resolve this?
Thanks
As it turns out com.google.common.collect is part of com.google.guava
With that find in hand I found a solution that works. For whatever reason dagger-compiler was not resolving its own dependency, which is com.google.guava.
My solution consists of excluding the guava dependency from the compiler and adding it to the annotationProcessor path. I also exclude find bugs for my case as an older version is a dependency in our test project.
annotationProcessor ('com.google.guava:guava:22.0'){
exclude group: 'com.google.code.findbugs'
}
annotationProcessor('com.google.dagger:dagger-compiler:2.13') {
exclude group: 'com.google.guava'
}
I've the below dependence in my Android app build.gradle
compileSdkVersion 25
buildToolsVersion "25.0.2"
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.firebase:firebase-jobdispatcher-with-gcm-dep:0.6.0'
compile 'com.google.firebase:firebase-appindexing:10.0.1'
compile 'com.google.firebase:firebase-ads:10.0.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
}
but getting an error about versions compatibility, as shown below, what is the one to be changed here, i could not figure it out :(
I had same problem what i did was compile the higher version of libraries ,which were creating this error,in app:gradle only.
for example in your case
compile 'com.android.support:mediarouter-v7:25.0.0'
Add this in app:gradle.
There may be more like this mediarouter libraries if it still give error add them jst like this(making them higher version).
First you need to find out where's what consists of a conflicting version of the library. The easiest way to do so is to:
Open Terminal pane in your Android Studio.
Type in: ./gradlew androidDependencies
Find the row that represents the ENCLOSING library consisting of a conflict.
Then just use exclude statement for the conflicting library, like so:
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
(the example assuming com.android.support.test.espresso:espresso-core:2.2.2 was the ENCLOSING library, and com.android.support:support-annotations being the conflict)
I have tried to add a Google Map fragment to my android app. I add the dependency
compile 'com.google.android.gms:play-services-maps:8.1.0'
However when I try to sync the gradle build file I get the error
Warning:Conflict with dependency 'com.android.support:support-annotations'.
Resolved versions for app (22.2.0) and test app (23.0.1) differ.
On the advice of another stack overflow answer we ran the Gradle dependencies report, and found that the only package that includes the module 22.2.0 is the google play one itself.
I have tried to exclude the module but this is to no avail.
Has anyone solved this problem? Any help would be much appreciated.
I attach the relevant part of the build.gradle file
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
//./compile 'com.android.support:appcompat-v7:19.1.0'
androidTestCompile ('com.android.support.test:runner:0.4') {
exclude module: 'support annotations'
}
// Set this dependency to use JUnit 4 rules
androidTestCompile ('com.android.support.test:rules:0.4') {
exclude module: 'support annotations'
}
// Set this dependency to build and run Espresso tests
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.1') {
exclude module: 'support annotations'
}
// Set this dependency to build and run UI Automator tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
androidTestCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services-maps:8.1.0'
}
You are not excluding the support annotations module from your testing libraries because of a small typo. Change "support annotations" to "support-annotations" in your exclude statements.
exclude module: 'support-annotations'
Huh! Faced this issue in the morning and now seeing this question.
I resolved by adding the following additional dependency:
androidTestCompile 'com.android.support:support-annotations:22.+'
I was not sure of the correct resolving version thereby kept with wildcard '+', if you are sure replace the wildcard with the right one.
I'm trying to integrate espresso into my application for ui testing. Here are my dependencies in Gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.1'
compile 'com.github.bumptech.glide:okhttp-integration:1.3.1#aar'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.android.support:cardview-v7:21.+'
compile 'com.android.support:recyclerview-v7:21.+'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2'
compile 'com.android.support:support-annotations:22.2.0'
androidTestCompile 'com.android.support.test:runner:0.3'
compile project(':common')
compile project(':service')
}
So all my espresso dependencies are included. However when I try to build I get this error:
Warning:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (22.2.1) and test app (22.2.0) differ.
Has anyone encountered this? I've found it reported here however there's no resolution. Does anyone have a fix for this?
New version of espresso-contrib 2.2.2 library has now dependency on com.android.support:appcompat-v7:23.1.1 resulting into conflict when using different version of appcompat-v7 in our compile time dependency like below:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
}
To avoid conflict when we exclude appcompat-v7 dependency from espresso-contrib like below it breaks again due to some value dependencies on design support lib.
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
exclude module: 'appcompat-v7'
}
Error:
Error:(69) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Display1'.
So, the solution to above problem is to exclude 'design-support' lib depedency from espresso-contrib like below:
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
exclude module: 'design'
}
That solves the conflict problem!
For more detailed version of the answer you could check my other answer
So after a lot of digging around, I found I needed to change the dependency for the support annotations.
So I needed to change
compile 'com.android.support:support-annotations:22.2.0'
to
androidTestCompile 'com.android.support:support-annotations:22.+'
Latest versions of androidTest dependencies depend on appropriate version of support-annotations lib. In my case it is:
androidTestCompile 'com.android.support.test:runner:0.4'
androidTestCompile 'com.android.support.test:rules:0.4'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
androidTestCompile 'org.mockito:mockito-core:2.0.31-beta'
Also, as a workaround you can add the next code in your build.gradle, android{} section:
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:23.0.1'
}
}
In the Jake Wharton U2020 application it is solved in the next way
Add to you gradle.build file
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:23.0.1'
}
}
I had to combine the following versions for L release after receiving a similar dependency conflict between project and test app:
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
androidTestCompile 'com.android.support.test:runner:0.4'
androidTestCompile 'com.android.support.test:rules:0.4'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
}
useLibrary was needed since we use org.apache.http imports, see https://github.com/bitstadium/HockeySDK-Android/issues/80
The problem is in this file:
android-sdk\extras\android\m2repository\com\android\support\test\runner\0.3\runner-0.3.pom
here:
<dependency>
<groupId>com.android.support</groupId>
<artifactId>support-annotations</artifactId>
<version>22.2.0</version>
<scope>compile</scope>
</dependency>
if you set 22.2.1 instead 22.2.0 it will work
As stated in the google documentation:
https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Resolving-conflicts-between-main-and-test-APK
The way to resolve is to explicitly set the support library in androidTestCompile to the version you are using in the project.
if for example you are using support library version 25.0.1 just add
androidTestCompile 'com.android.support:support-annotations:25.0.1'
in your build.gradle configuration
just change compile com.android.support:support-annotations:22.2.0 to 23.0.1
if want to use 2.2.1 version
I'm using Android Studio 0.6.1, with Crouton library and today after gradle sync I got next error:
Error:A problem occurred configuring root project 'project_name'.
Module version de.keyboardsurfer.android.widget:crouton:1.8.4 depends on libraries but is not a library itself
That's going on?
This issue due to com.android.support-v4 recent update.
So I changed
compile 'com.android.support:support-v4:20.+'
to
compile 'com.android.support:support-v4:19.1.+'
and crouton works fine
Different workaround is to use #aar:
compile('de.keyboardsurfer.android.widget:crouton:1.8.4#aar') {
exclude group: 'com.google.android', module: 'support-v4'
}
My solution according to #Revedko answer, using #aar and change all supports to version lower than 21 -> 20.+
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.loopj.android:android-async-http:1.+'
compile "com.bugsense.trace:bugsense:3.5"
compile('de.keyboardsurfer.android.widget:crouton:1.8.4#aar') {
exclude group: 'com.google.android', module: 'support-v4'
}
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:5.0.77'
}