如何使现代Multidex与旧版API上的测试结合使用

问题描述

我有一个使用Multidex设置的应用程序,似乎可以在较旧的Android API上加载和运行,但是,有时我从检测到的测试运行程序中收到错误,发现它找不到任何测试。我可以找到有关如何将multidex添加到Android应用程序的详细信息,但是有几种解决方案取决于所使用的支持库,而且似乎没有一个解决方案可以使用当前推荐的AndroidX库直接解决使用multidex运行测试的问题。在Android 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或缩小功能。为了启用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'
}

我的清单定义了一个从android:name属性中的androidx.multidex.MultiDexApplication继承的类。

我已经提到过为Test应用程序在AndroidManifest.xml中添加multidex测试运行器,但是我目前没有明确的清单,它似乎只是在旧的Android支持库的上下文中,而不是AndroidX。我需要做些什么才能使仪器化测试能够在API级别16-19上与Multidex和AndroidX一起使用?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)