Android AssertJ 1.0.0 with Android gradle 1.1.1
Asked Answered
A

3

8

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

Aside answered 27/2, 2015 at 9:37 Comment(0)
B
7

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'
}
Belshazzar answered 27/2, 2015 at 21:48 Comment(1)
Doesn't work for me. I still see a lot error: package org.assertj.android.api does not exist import static org.assertj.android.api.Assertions.assertThat;Aside
C
1

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://mcmap.net/q/136232/-resolved-versions-for-app-22-0-0-and-test-app-21-0-3-differ

Cathe answered 3/9, 2015 at 22:37 Comment(2)
The question and answer is already outdated as for me. I don't have any issues in having assertj in the project now. As well AssetJ for Android already went two version upAside
The issue still exists as far as the current version of AssertJ (1.1.0) does not use the latest version of support-annotations (23.0.1). The latest versions of Espresso and com.android.support.test:rules also use old versions of support-annotations. I found your question came up when I searched for the error.Cathe
G
-2

You need to change:

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

to:

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

Also ensure that your test folder is called test and not androidTest

Ginnifer answered 27/4, 2015 at 13:4 Comment(1)
but compile is used for release versions not test version so release code will have assertj things?Pierro

© 2022 - 2024 — McMap. All rights reserved.