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 an android project where I use espresso to define tests. It all worked well until now but after upgrading to AppCompat 23.2.1 (from AppCompat 23.0.1) the execution of the tests always crashes.
My build.gradle dependencies:
dependencies {
// Ok Config
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:support-annotations:23.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support:support-annotations:23.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
The project compiles and executes ok, but when I try to run a test it crashes with this error:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
Despite the text of the error I am using a descendant theme of Theme.AppCompat, so I don't understand the error message at all.
Anyone had the same problem? It seems to be any problem with the dependencies of appcompat and espresso, but I'm unable to find it and solve my problem.
Any ideas?
Thanks!
I think that the main problem is that espresso modules use a different support library than the one used in my project, so when I try to run the test the tests crashes.
Finally I've resolved it excluding the support library of all the espresso modules, to force them to use the support library of my project. And now everything works great. Hope this could help anyone!
My gradle looks like this:
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:support-annotations:23.2.1'
androidTestCompile ('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support'
}
androidTestCompile ('com.android.support.test:rules:0.5') {
exclude group: 'com.android.support'
}
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude group: 'com.android.support'
}
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude group: 'com.android.support'
}
androidTestCompile ('com.android.support.test.espresso:espresso-intents:2.2.2') {
exclude group: 'com.android.support'
}
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 have tried almost every trick in the book.
ResolutionStrategy.force
Excluding modules
But nothing seems to work, below is my build.gradle. I'm using Gradle version 1.2.3. Can someone please throw light on what else could be wrong with my code.
The only thing I haven't tried is changing version of Gradle.
It's a very basic Espresso Test case. Thanks!
apply plugin: 'com.android.application'
android {
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:22.1.0'
}
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.rasika.job"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
}
I forked android-topeka google sample and updated appcompat version to 23.1.0, same message:
Warning:Conflict with dependency
'com.android.support:support-annotations'. Resolved versions for app
(23.1.0) and test app (23.0.1) differ.
I added:
androidTestCompile 'com.android.support:support-annotations:23.1.0'
Now both resolve to 23.1.0, the warning is gone, and the app and tests still work.
I'm not sure that it's the better solution, so I'm searching for another but found your question.
Update: Read this good explanation by PaulR.
Update2: Confirmed, android-testing google sample does it.
// Testing-only dependencies
// Force usage of support annotations in the test app, since it is internally used by the runner module.
androidTestCompile 'com.android.support:support-annotations:23.0.1'
Update3: Another good response by CommonsWare.
Check your specific versions/conflicts/resolutions using:
./gradlew -q yourmodule:dependencies
Appcompat is 22.1.1 in your case but you are forcing 22.1.0.
Update4:
Dependency conflict explained at The Android Build System (Android Dev Summit 2015).
Resolving conflicts between main and test APK
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).
To make the build succeed, just make sure both APKs use the same
version. If the error is about an indirect dependency (a library you
didn't mention in your build.gradle), just add a dependency for the
newer version to the configuration ("compile" or "androidTestCompile")
that needs it. You can also use Gradle's resolution strategy
mechanism. You can inspect the dependency tree by running ./gradlew
:app:dependencies and ./gradlew :app:androidDependencies.
I solved the conflict by adding dependency:
androidTestCompile 'com.android.support:support-annotations:23.2.0'
I had the same issue, solved by this:
// build.gradle
...
android {
...
defaultConfig {
...
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
dependencies {
...
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2') {
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test:runner:0.3') {
// Necessary if your app targets Marshmallow (since the test runner
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
}
solution was found here:
https://github.com/codepath/android_guides/wiki/UI-Testing-with-Espresso
UPDATE:
finally dependencies block in my build.gradle looks like this:
dependencies {
...
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:design:23.2.1'
...
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.2') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test:rules:0.5') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support:support-annotations:23.2.1') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test.uiautomator:uiautomator-v18:2.1.2') {
exclude group: 'com.android.support'
}
}
This happened to me recently when adding the uiautomator. To fix this issue, you need to figure out which dependency or dependencies is using the outdated module. You can do this by wrapping each androidTestCompile dependency into a block, like so:
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2') {
transitive = false;
}
This might break some other things though, so you need to be careful. I was able to pinpoint exactly which two of the dependencies was causing this issue for me, and just adding this blocking mechanism to those.
I solved the conflict by excluding the support-annotation library from both runner and espresso-core dependencies:
androidTestCompile 'com.android.support.test:runner:0.5',{
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2'){
exclude group: 'com.android.support', module: 'support-annotations'
}
Add follow codes to your dependency block in build.gradle file
compile 'com.android.support:support-annotations:23.2.1'
testCompile 'com.android.support:support-annotations:23.2.1'
androidTestCompile 'com.android.support:support-annotations:23.2.1'
Add this to your main build.gradle:
allprojects {
...
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:23.1.1'
}
...
}
androidTestCompile change to testCompile. And remind dont't change it to compile, just need this dependencies to be compiled into our debug APK or test APK.
For me this worked fine
dependencies {
androidTestCompile 'com.android.support:support-annotations:23.1.1'
}
I solved the conflict by adding dependency:
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
...
androidTestCompile 'com.android.support:support-annotations:23.2.1'
In also got into the Problem saying
Could not resolve
com.android.support:support-annotations:23.1.0
and tried to find in other servers ,
But what resolved my problem is adding :
google-service.json
file from
https://developers.google.com/mobile/add
and copy and paste it into
YourAndroidProject/app
Then recompile it and i hope your code will fly
Use this for resolving conflict
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
I solved the conflict by adding dependency:
androidTestCompile "com.android.support:support-annotations:26.0.0-beta1"
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'
}