我正在尝试将android项目升级到sdk 27​​,因此尝试将robolectric升级到3.8。现在,当我尝试运行测试时,我一直挂在那个错误上:

java.lang.RuntimeException: java.util.zip.ZipException: error in opening zip file

at org.robolectric.res.Fs$JarFs.<init>(Fs.java:96)
at org.robolectric.res.Fs.fromJar(Fs.java:27)
at org.robolectric.internal.SdkEnvironment.createRuntimeSdkResourcePath(SdkEnvironment.java:31)
at org.robolectric.internal.SdkEnvironment.getSystemResourceTable(SdkEnvironment.java:22)
at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:332)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:245)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:130)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:42)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:84)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:219)
at java.util.zip.ZipFile.<init>(ZipFile.java:149)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:130)
at org.robolectric.res.Fs$JarFs.<init>(Fs.java:94)
... 27 more


我认为gradle中有趣的部分是这样的:

android {
  compileSdkVersion 27
  buildToolsVersion '27.0.3'
  defaultConfig {
    minSdkVersion 21
    targetSdkVersion 27
  }
}

dependencies {
  testImplementation 'org.robolectric:robolectric:3.8'
}


我已经尝试清除依赖项并删除gradle包装器。我非常感谢您能给我的每条小费。如果您需要更多信息才能帮助我,请提出要求。

最佳答案

删除您的主目录和项目的根目录中的.gradle目录,然后尝试再次构建。(from:Error when I try to generate a libgdx projet

10-08 06:02
查看更多