我添加了multidex。
如果我从包或类中运行测试,则可以正常工作。
但是,从控制台测试不起作用。 正在构建应用。
logcat的一部分:
Task :app:connectedDebugAndroidTest
...
03:04:39 I/RemoteAndroidTest: Running am instrument -w -r com.app.test/android.support.test.runner.MultiDexTestRunner on D5803 - 6.0.1
03:04:39 V/ddms: execute: running am instrument -w -r com.app.test/android.support.test.runner.MultiDexTestRunner
03:04:40 V/InstrumentationResultParser: INSTRUMENTATION_RESULT: shortMsg=java.lang.ClassNotFoundException
03:04:40 I/InstrumentationResultParser: test run failed: 'Instrumentation run failed due to 'java.lang.ClassNotFoundException''
Starting 0 tests on D5803 - 6.0.1
Tests on D5803 - 6.0.1 failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'
03:04:40 I/XmlResultReporter: XML test result file generated at D:\user\Projects\app\app-Android\app\build\outputs\androidTest-results\connected\TEST-D5803 - 6.0.1-app-.xml. Total tests 0,
03:04:40 V/InstrumentationResultParser: INSTRUMENTATION_RESULT: longMsg=java.lang.ClassNotFoundException: Didn't find class "android.support.test.runner.MultiDexTestRunner" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.app.test-1/base.apk", zip file "/data/app/com.app.test-1/base.apk"],nativeLibraryDirectories=[/data/app/com.app.test-1/lib/arm, /data/app/com.app.test-1/lib/arm, /vendor/lib, /system/lib]]
03:04:40 V/InstrumentationResultParser: INSTRUMENTATION_CODE: 0
03:04:40 V/InstrumentationResultParser:
03:04:40 V/ddms: execute 'am instrument -w -r com.app.test/android.support.test.runner.MultiDexTestRunner' on 'YT9118WPMT' : EOF hit. Read: -1
03:04:40 V/ddms: execute: returning
com.android.builder.testing.ConnectedDevice > No tests found.[D5803 - 6.0.1] 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).
03:04:40 I/XmlResultReporter: XML test result file generated at D:\user\Projects\app\app-Android\app\build\outputs\androidTest-results\connected\TEST-D5803 - 6.0.1-app-.xml. Total tests 1, failure 1,
03:04:40 V/ddms: execute: running pm uninstall com.app.test
03:04:42 V/ddms: execute 'pm uninstall com.app.test' on 'YT9118WPMT' : EOF hit. Read: -1
03:04:42 V/ddms: execute: returning
我的build.gradle的一部分:
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.MultiDexTestRunner"
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
multiDexKeepProguard file('proguard-multidex-rules.pro')
multiDexEnabled true
}
}
我该如何解决问题?