Issue
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 selectInspection '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.
Solution
Just add the following to your build.gradle (App) file:
configurations.all {
resolutionStrategy.force "junit:junit:$junit_version"
}
dependencies {
...
}
Answered By - Bohsen