在我的 android 应用程序中,我启用了 multidexing。该应用程序在模拟器上运行良好。我正在使用 robotsium 来测试应用程序。但是当我执行仪器测试用例时,有时测试会通过,但大多数情况下它们在系统重启后也会失败。在它通过和失败之间没有代码更改。
默认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 测试运行。我无法理解哪个依赖项弄乱了代码。除此之外,代码的随机故障令人怀疑。请帮忙。