今天在编译的时候遇到一个奇怪的报错:



这他么是啥?
然后找了一圈,终于找到了:

不推荐使用AndroidJUnit4.class:如何使用androidx.test.ext.junit.runners.AndroidJUnit4?
For my instrumentation tests I was using

@RunWith(AndroidJUnit4.class)

from

androidx.test.runner.AndroidJUnit4;

in order to establish my test cases. Now this line gets marked as deprecated with the hint to use >AndroidJUnit4 from

import androidx.test.ext.junit.runners.AndroidJUnit4

然后解决方法是:

However if I try to import AndroidJUnit4 from the named package I get the error, that ext can not be resolved.
Do you have an idea, what package should be included in gradle to resolve this issue?
According to the documentation for AndroidJUnit4, the gradle file should contain the following line:

androidTestImplementation 'androidx.test.ext:junit:1.1.0'
After adding this, everything worked for me.
If it still doesn't work, make sure that you clean and/or rebuild your project.

就是在gradle文件dependencies里添加:

androidTestImplementation 'androidx.test.ext:junit:1.1.0'

就好了

Last modification:April 15, 2020
If you think my article is useful to you, please feel free to appreciate