Android Studio cannot find package when importing org.robolectric

I am using butterknife: 8.5.1 package, when I want to add robolectric gradle says com.google.guava has conflit:

Error: Conflict with dependency 'com.google.guava: guava' in project ': app'. Permitted versions for app (18.0) and test app (20.0) are different. See http://g.co/androidstudio/app-test-app-conflict for details .

I checked the dependencies, and because ButterKnife uses guava

18, so I use

configurations.all {
    resolutionStrategy {
        force 'com.google.guava:guava:20.0'
    }
}

      

try to avoid, now gradle will build without errors.

However, when I want to use a package, Android Studio always complains about

import org.robolectric.Robolectric;

It says he cannot find org.robolectric

. I have no idea what is going on, can anyone help? Thank you so much.

Then I also tried

exclude group: 'com.google.guava', module: 'guava'

      

also the same result

I suspect it has something to do with com.google.guava

, but I can't figure out why it can't find the package. I see the robolectric package under "external libraries"

+3


source to share


2 answers


In fact, I found it because my test is in the androidTest folder, not the test, which makes the package unavailable.



+1


source


Try this: in

dependencies {
compile 'org.robolectric:robolectric:3.4'     // instead of TestCompile
}

      



This worked for me.

0


source







All Articles