Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Unresolved reference when using junit 4.13

After updating junit version to 4.13 in gradle dependencies, classes and annotations like Assert, @Test, etc. under the junit package are displayed as red when used in my code. Lint check says:

Unresolved reference: <any junit class>

However, when I build and run my tests, it will build and run just fine.

I have tried:

  • restarting Android Studio
  • Invalidate caches and restart
  • Clean and rebuild project
  • added testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"

What works is downgrading junit to 4.12. How to get rid of this lint error, without downgrading version?

Update:

  • When I check ALT + ENTER options and select Inspection 'Unresolved reference, in wrong test scope' options > Suppress 'IncorrectScope' for file <name of file>, it gets rid of these lint errors for that particular file. I still like to solve this problem without using Suppress though.
  • According to this issue, it looks like this bug is not fixed yet. For now I'm downgrading to 4.12.
  • Removing both espresso and runner from dependencies also fixes the problem.
like image 837
Loremar Marabillas Avatar asked Jan 05 '20 08:01

Loremar Marabillas


People also ask

How to fix Unresolved reference Android Studio?

If you still see the unresolved reference error after fixing the problem, try to build your Android application with Command + F9 for Mac or Control + F9 for Windows and Linux. The error should disappear after the build is completed.


1 Answers

Just add the following to your build.gradle (App) file:

configurations.all {
    resolutionStrategy.force "junit:junit:$junit_version"
}

dependencies {
...
}
like image 167
Bohsen Avatar answered Oct 21 '22 05:10

Bohsen