gpt4 book ai didi

java - NoClassDefFoundError 与 AndroidJUnitRunner @java.util.Objects 与 MultiDex-App

转载 作者:行者123 更新时间:2023-11-28 20:53:06 26 4
gpt4 key购买 nike

几天以来,我一直在为我们的 MultiDex 应用程序中的 NoClassDefFoundError 和 AndroidJUnitRunner 而苦苦挣扎......

因为我们想开始使用 Espresso 进行点击测试,所以我们将 TestRunner 从“MultiDexTestRunner”更改为“AndroidJUnitRunner”。通过此更改,我们在 API 19 下遇到了一些设备问题。当我们执行 @SmallTests 时,我们得到的响应是“未执行测试”导致 NoClassDefFoundError

在我们的 Logcat 中,我们得到以下信息:

06-17 14:19:13.832 26531-26779/com.xxxxxx.debug E/AndroidRuntime: FATAL EXCEPTION: Instr: com.xxxxxxxx.test.WakefulTestRunner
java.lang.ExceptionInInitializerError
at android.support.test.internal.runner.TestRequestBuilder.addFromRunnerArgs(TestRequestBuilder.java:713)
at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:350)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:260)
at com.xxxxxxxxxx.test.WakefulTestRunner.onStart(WakefulTestRunner.java:54)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1619)
Caused by: java.lang.NoClassDefFoundError: java.util.Objects
at android.support.test.internal.runner.TestSize.hashCode(TestSize.java:212)
at java.util.HashMap.put(HashMap.java:390)
at java.util.HashSet.add(HashSet.java:95)
at java.util.HashSet.<init>(HashSet.java:77)
at android.support.test.internal.runner.TestSize.<clinit>(TestSize.java:65)
at android.support.test.internal.runner.TestRequestBuilder.addFromRunnerArgs(TestRequestBuilder.java:713) 
at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:350) 
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:260) 
at com.xxxxxxxx.test.WakefulTestRunner.onStart(WakefulTestRunner.java:54) 
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1619) 

这是我们的 WakefulTestRunner 所需的部分:

public class WakefulTestRunner extends AndroidJUnitRunner {

private PowerManager.WakeLock wakeLock;
private KeyguardManager.KeyguardLock keyguardLock;

@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle arguments) {
MultiDex.install(getTargetContext());
super.onCreate(arguments);

String simpleName = WakefulTestRunner.class.getSimpleName();

// Unlock the device so that the tests can input keystrokes.
keyguardLock = ((KeyguardManager) getContext().getSystemService(KEYGUARD_SERVICE)).newKeyguardLock(simpleName);

// Wake up the screen.
int levelAndFlags = android.os.PowerManager.FULL_WAKE_LOCK
| android.os.PowerManager.ACQUIRE_CAUSES_WAKEUP
| android.os.PowerManager.ON_AFTER_RELEASE;
wakeLock = ((PowerManager) getContext().getSystemService(POWER_SERVICE)).newWakeLock(levelAndFlags, simpleName);
}

@Override
public void onStart() {
runOnMainSync(new Runnable() {
@Override
public void run() {
keyguardLock.disableKeyguard();
wakeLock.acquire();
}
});

super.onStart();
}

我们还在 build.gradle 中排除了很多不同的东西,但没有任何帮助:

configurations {
// This dependency set is for annotation processors.
// They're added below directly to the java compiler.
apt
androidTestCompile.exclude group: 'com.android.support', module: 'support-v4'
androidTestCompile.exclude group: 'com.android.support', module: 'recyclerview-v7'

androidTestCompile.exclude group: 'com.android.support', module: 'support-v13'
androidTestCompile.exclude group: 'com.android.support', module: 'appcompat-v7'
androidTestCompile.exclude group: 'com.android.support', module: 'cardview-v7'
}

defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode versionMajor * 10000 + versionMinor * 100 + versionMicro
versionName "${versionMajor}.${versionMinor}.${versionMicro}"
multiDexEnabled true

//intended to fix install issue -505 (https://code.google.com/p/android/issues/detail?id=189079)
applicationId = "com.xxxxxxxx"

testInstrumentationRunner "com.xxxxxxxxx.test.WakefulTestRunner"
}

最佳答案

这是 AndroidJUnitRunner 中的一个错误。 https://code.google.com/p/android/issues/detail?id=213677

解决方法是不对 API 19 之前的设备使用测试大小标志。

API 崩溃<19

./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.size=small

适用于所有设备

./gradlew connectedAndroidTest

关于java - NoClassDefFoundError 与 AndroidJUnitRunner @java.util.Objects 与 MultiDex-App,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37882021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com