Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android AssertJ 1.0.0 with Android gradle 1.1.1

Here is part of my build.gradle that has conflict:

...
dependencies {
  classpath 'com.android.tools.build:gradle:1.1.1'
}
...
testCompile( 'com.squareup.assertj:assertj-android:1.0.0' )
...

The issue that I see in log:

WARNING: Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (21.0.3) and test app (20.0.0) differ.

Apparently it removes conflicting dependency from the classpath. I'm not sure if it is gradle or android gradle plugin.

I've tried next:

  testCompile( 'com.squareup.assertj:assertj-android:1.0.0' ) {
    exclude group: 'com.android.support', module: 'support-annotations'
  }

But I still have compilation errors so dependency is excluded.

I've tried next:

configurations.all {
  resolutionStrategy {
    // fail eagerly on version conflict (includes transitive dependencies)
    // e.g. multiple different versions of the same dependency (group and name are equal)
    failOnVersionConflict()

    // force certain versions of dependencies (including transitive)
    //  *append new forced modules:
    force 'com.android.support:support-annotations:21.0.3'
    //  *replace existing forced modules with new ones:
    forcedModules = ['com.android.support:support-annotations:21.0.3']
  }
}

But looks like it doesn't work since it is not failing on the first conflict and I still have compilation errors.

What will be your suggestions?

UPDATE What do I mean by removing dependency - I see a lot of compile errors that assertj not found

like image 221
Eugen Martynov Avatar asked Feb 27 '15 09:02

Eugen Martynov


2 Answers

I ran into the same issue. This fixed it for me:

testCompile('com.squareup.assertj:assertj-android:1.0.0'){
    exclude group: 'com.android.support', module:'support-annotations'
}
like image 185
Cain Wong Avatar answered Nov 10 '22 08:11

Cain Wong


The accepted answer didn't work for me. However, adding the following did work for me:

androidTestCompile 'com.android.support:support-annotations:23.0.1'

and:

testCompile 'com.android.support:support-annotations:23.0.1'

Based on https://stackoverflow.com/a/29947562/2832027

like image 43
TTransmit Avatar answered Nov 10 '22 07:11

TTransmit