我用Multidex设置了一个应用程序,似乎可以加载并使用较旧的Android API,但是,我有时会从仪器化的测试运行器中收到错误,因为它找不到任何测试。我可以找到如何将multidex添加到Android应用程序的详细信息,但根据使用的支持库,有几种解决方案,似乎没有一种解决方案可以直接解决使用当前推荐的AndroidX库运行multidex的测试问题。在安卓API 19级上,我目前得到这个错误:
$ ./gradlew connectedCheck
> Task :app:connectedDebugAndroidTest
Starting 0 tests on API-19(AVD) - 4.4.2
com.android.build.gradle.internal.testing.ConnectedDevice > No tests found.[API-19(AVD) - 4.4.2] FAILED
No tests found. This usually means that your test classes are not in the form that your test runner
expects (e.g. don't inherit from TestCase or lack @Test annotations).
在API级别为21的模拟器上运行此程序可成功运行所有测试。我没有启用Proguard或minify。为了启用Multidex,我进行了以下更改。我在应用程序的build.gradle中添加了以下内容:
android {
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
}
dependencies {
implementation "androidx.multidex:multidex:2.0.1"
androidTestImplementation 'org.mockito:mockito-core:3.4.6'
androidTestImplementation 'com.linkedin.dexmaker:dexmaker:2.28.0'
androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.28.0'
}
我的清单定义了一个继承自
androidx.multidex.MultiDexApplication
在android:name属性中。
我看到有人提到要为test应用程序的AndroidManifest.xml添加一个多线程测试运行器,但我目前还没有明确的清单,而且它似乎只在旧的Android支持库的上下文中,而不是AndroidX。我需要做些什么才能在API 16-19级上使用Multidex和AndroidX进行仪器测试?