gpt4 book ai didi

android - MultiDexApplication 的使用导致 Application 类的 Robolectric 测试中断

转载 作者:IT老高 更新时间:2023-10-28 23:08:27 26 4
gpt4 key购买 nike

使用 gradle def (https://plus.google.com/+IanLake/posts/JW9x4pcB1rj) 支持 v4-r21 添加 Multi dex 支持

apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion "20.0.0"

defaultConfig {
applicationId "info.osom.multidex"
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

dexOptions {
preDexLibraries = false
}

afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = []
}
dx.additionalParameters += '--multi-dex'
dx.additionalParameters += "--main-dex-list=$projectDir/multidex.keep".toString()
}

现在这适用于应用程序本身,我能够构建和部署,但是当我为我的 Application 类运行 robolectric 测试时,ZipUtils 失败(在 MultiDex.java 中捕获)。其他测试运行良好。这是痕迹 -

Caused by: java.lang.RuntimeException: Multi dex installation failed (/Users/Code/android-code/android/. (Is a directory)). at android.support.multidex.MultiDex.install(MultiDex.java:178) at android.support.multidex.MultiDexApplication.attachBaseContext(MultiDexApplication.java:39) at android.app.Application.attach(Application.java:181) at org.fest.reflect.method.Invoker.invoke(Invoker.java:112) at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:155) at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:430) at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:236) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69) at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48) at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32) at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93) at com.sun.proxy.$Proxy2.processTestClass(Unknown Source) at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105)

最佳答案

添加 multi-dex shadow 作为您的依赖项:

testCompile "org.robolectric:shadows-multidex:3.0"

这将模拟 MultiDex.install 调用并且什么都不做,因为 Robolectric 中没有 dex

关于android - MultiDexApplication 的使用导致 Application 类的 Robolectric 测试中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26512170/

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