问题描述
页面 http://developer.android.com/tools/building/multidex.html#testing 建议
dependencies {
compile 'com.android.support:multidex:1.0.1'
androidTestCompile 'com.android.support:multidex-instrumentation:1.0.1'
}
android {
defaultConfig {
multiDexEnabled true
testInstrumentationRunner "android.support.multidex.MultiDexTestRunner"
}
}
但是在运行测试时会产生ClassNotFoundException.
But that produces a ClassNotFoundException when the tests are run.
API文档和dexdump显示存在com.android.test.runner.MultiDexTestRunner.
The API documentation and dexdump show that there is com.android.test.runner.MultiDexTestRunner.
因此,如果我不相信文档,而是指定
So if I disbelieve the documentation and instead specify
dependencies {
compile 'com.android.support:multidex:1.0.1'
androidTestCompile 'com.android.support:multidex-instrumentation:1.0.1'
}
android {
defaultConfig {
multiDexEnabled true
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}
}
然后我得到
com/company/myapp/MyApp; had used a different Landroid/support/multidex/MultiDexApplication; during pre-verification
...
IllegalAccessExceptionIllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
我怀疑文档页面是错误的,正确的路径是com.android.test.runner.MultiDexTestRunner ...另外我还有其他问题.
I suspect that the doc page is wrong and the correct path is com.android.test.runner.MultiDexTestRunner ... plus I have some other issue.
请注意,multidex应用程序运行良好.不知何故,第二个MultiDexApplication已包含在测试apk中.
Note the multidex application works fine. Somehow a second MultiDexApplication is included in the test apk.
问题:
哪个是MultiDexTestRunner的正确路径?为什么我在测试apk中得到第二个MultiDexApplication?
Questions:
Which is the correct path for MultiDexTestRunner?Why am I getting a second MultiDexApplication in the test apk?
推荐答案
更新:这是解决方法.这是一种常见的模式,当您看到这样的错误消息使用了不同的L< package>时;在预验证期间
,您需要在运行测试时排除软件包.
UPDATE: here's the fix. That's a common pattern, when you see such error message had used a different L<package>; during pre-verification
, you need to exclude the package when running the test.
build.gradle
android {
// ...
defaultConfig {
// ...
multiDexEnabled true
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}
}
dependencies {
// ...
// Need to exclude this when running test
androidTestCompile('com.android.support:multidex-instrumentation:1.0.1') {
exclude group: 'com.android.support', module: 'multidex'
}
}
Application.java
public class Application extends android.app.Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
这篇关于哪个软件包适合MultiDexTestRunner?android.support.multidex或com.android.test.runner的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!