Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio can't find package when import org.robolectric

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

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

I checked the dependencies, and because ButterKnife is using 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 the package, Android Studio always complains at

import org.robolectric.Robolectric;

It says it can't find org.robolectric. I have no idea what's going on, can someone help? Thank a lot.

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 understand why it can't find the package. I can see robolectric package under "external libraries"

like image 757
Wingzero Avatar asked Nov 30 '25 01:11

Wingzero


1 Answers

Actually, I found it's because my test is under androidTest folder, not test, which causes the package unavailable.

like image 131
Wingzero Avatar answered Dec 01 '25 15:12

Wingzero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!