Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 在启用multidexing的情况下,Instrumentation测试随机失败大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的 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;' @L_772_8@
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测试.我无法理解哪个依赖项会弄乱代码.除此之外,代码随机失败是持怀疑态度的.请帮忙.

解决方法

找到了相同的解决方案,即设置dex验证和优化参数.您还可以将dalvik.vm.dexopt-flags设置为v = n,以使框架通过-Xverify:none -Xdexopt:验证以禁用验证.

执行:

adb sHell setprop dalvik.vm.dexopt-flags v=n,o=v
adb sHell stop installd
adb sHell start installd

执行命令后不得不等待几秒钟.具有多索引的仪表测试可以顺利运行.

大佬总结

以上是大佬教程为你收集整理的android – 在启用multidexing的情况下,Instrumentation测试随机失败全部内容,希望文章能够帮你解决android – 在启用multidexing的情况下,Instrumentation测试随机失败所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。