在我的android应用程序中,我启用了多重索引。该应用程序在仿真器上运行良好。我正在使用robotium来测试应用程序。但是当我执行仪器测试用例时,有时测试通过,但大多数情况下,它们在系统重新启动后也会失败。它通过和失败之间没有代码改变。仪器测试随着多重索引启用而失败
默认配置的gradle:
android {
defaultConfig {
applicationId "com.example.androidapp"
minSdkVersion 16
targetSdkVersion 23
multiDexEnabled true
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
testProguardFile "proguard-test.txt"
}
}
另外添加依赖于测试:
androidTestCompile fileTree(dir: 'libs', include:'robotium-solo-5.3.0.jar')
androidTestCompile ('com.android.support:multidex-instrumentation:1.0.1') {
exclude group: 'com.android.support', module: 'multidex' }
在AndroidManifest.xml我所提到的应用程序标记为:
<application
android:name="StartupActivity"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" ...../>
我已经扩展“StartupActivity”中的“android.support.multidex.MultiDexApplication”。的时候,仪器测试的情况下跌倒了,我得到以下错误:
INSTRUMENTATION_RESULT: shortMsg=java.lang.IllegalAccessError
INSTRUMENTATION_RESULT: longMsg=java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
INSTRUMENTATION_CODE: 0
在logcat中的错误信息是:
W/dalvikvm﹕ Class resolved by unexpected DEX: Lcom/example/androidapp/StartupActivity;(0xa695df08):0x9910e000 ref [Landroid/support/multidex/MultiDexApplication;] Landroid/support/multidex/MultiDexApplication;(0xa695df08):0x99a2c000
W/dalvikvm﹕ (Lcom/example/androidapp/StartupActivity; had used a different Landroid/support/multidex/MultiDexApplication; during pre-verification)
W/dalvikvm﹕ Unable to resolve superclass of Lcom/example/androidapp/StartupActivity; (540)
W/dalvikvm﹕ Link of class 'Lcom/example/androidapp/StartupActivity;' failed
D/AndroidRuntime﹕ Shutting down VM
W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa628c288)
测试类颇像:
public class HelloActivityTest extends ActivityInstrumentationTestCase2<HelloActivity> {
private Solo solo;
public HelloActivityTest() {
super(HelloActivityTest.class);
}
@Override
public void setUp() throws Exception {
setActivityInitialTouchMode(false);
solo = new Solo(getInstrumentation(), getActivity());
}
public void test1() {}
public void test2() {}
}
我我正在运行测试用例作为android测试。我无法理解哪个依赖关系搞乱了代码。除此之外,代码的随机失败是怀疑的。请帮忙。
我的团队成员对espresso测试和multidex有类似的评论。更多的是,它没有确定有测试运行multidex使能... – OceanLife
@OceanLife你有没有找到任何解决方案? – whitepearl
不,我们还没有。没有multidex,它是可靠的,因此我建议我们编译出一些分析库,这些库是作为临时解决方案来扩充的......只是为了回到不需要multidex。你的错误信息(意外的impl)让我想起了Java的SDK不兼容性错误,所谓的“VerifyError”(s)...在旅途中得到一些proguarding去除庞大的位... – OceanLife