Espresso-android jar - 'Error in opening zip file' in android studio 8.x

限于喜欢 提交于 2021-02-08 05:54:25

问题


I've been getting this error, I've tried the solution stated here: Android studio - Failed to complete gradle execution - error in opening zip file

This error is killing me, I've tried removing the .gradle folder. I've noticed that the .idea\libraries folder has a bunch of xml's in it and I've tried deleting that (thinking its storing something wrong) and that wasn't it either.

I've narrowed it down to the jars downloaded from the espresso-android site, espresso-1.1.jar and the test runners - I've verified that without them in the dependencies it works. And as soon as they've been added it doesn't. I can even add other dependencies and it works. So I don't know why these Jars are the exception but they don't work.

:app:compileDebugJava
error: error reading /Users/busyer_jonathan/AndroidStudioProjects/TestVersion/app/libs/testrunner-runtime-1.1.jar; error in opening zip file
error: error reading /Users/busyer_jonathan/AndroidStudioProjects/TestVersion/app/libs/testrunner-1.1.jar; error in opening zip file
error: error reading /Users/busyer_jonathan/AndroidStudioProjects/TestVersion/app/libs/testrunner-runtime-1.1.jar; error in opening zip file
error: error reading /Users/busyer_jonathan/AndroidStudioProjects/TestVersion/app/libs/testrunner-1.1.jar; error in opening zip file

:app:preDexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
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:214)
    at java.util.zip.ZipFile.<init>(ZipFile.java:144)
    at java.util.zip.ZipFile.<init>(ZipFile.java:158)
    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
    at com.android.dx.command.dexer.Main.processOne(Main.java:596)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
    at com.android.dx.command.dexer.Main.run(Main.java:230)
    at com.android.dx.command.dexer.Main.main(Main.java:199)
    at com.android.dx.command.Main.main(Main.java:103)
1 error; aborting

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Applications/Android Studio.app/sdk/build-tools/android-4.4W/dx --dex --output /Users/busyer_jonathan/AndroidStudioProjects/TestVersion/app/build/intermediates/pre-dexed/debug/testrunner-runtime-1.1-9d180daedad4578babced4673aa1a80a8f70f413.jar /Users/busyer_jonathan/AndroidStudioProjects/TestVersion/app/libs/testrunner-runtime-1.1.jar
  Error Code:
    1
  Output:

    UNEXPECTED TOP-LEVEL EXCEPTION:
    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:214)
        at java.util.zip.ZipFile.<init>(ZipFile.java:144)
        at java.util.zip.ZipFile.<init>(ZipFile.java:158)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:596)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
        at com.android.dx.command.dexer.Main.run(Main.java:230)
        at com.android.dx.command.dexer.Main.main(Main.java:199)
        at com.android.dx.command.Main.main(Main.java:103)
    1 error; aborting


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Here is my build file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.example.edu.testversion"
        minSdkVersion 16
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
        //testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'LICENSE.txt'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/json_simple-1.1.jar',
            'libs/testrunner-1.1.jar',
            'libs/testrunner-runtime-1.1.jar')
    compile files('libs/scribe-1.3.5.jar')
    compile 'com.android.support:support-v4:20.0.0'
    compile 'com.google.android.gms:play-services:5.0.77'
    compile 'com.android.support:appcompat-v7:20.0.0'
    androidTestCompile 'org.mockito:mockito-core:1.9.+'
    androidTestCompile 'org.objenesis:objenesis:1.2'
    //Espresso dependencies includes guava, hamcrest, dagger, javax annotation
    androidTestCompile 'com.google.guava:guava:14.0.1',
            'com.squareup.dagger:dagger:1.1.0',
            'org.hamcrest:hamcrest-integration:1.1',
            'org.hamcrest:hamcrest-library:1.1'
}

回答1:


The problem, I found, was that I was downloading the jars from the espresso site : https://code.google.com/p/android-test-kit/source/browse/#git by right clicking on them and clicking 'Save as'- which did indeed download the jars, they just did not work for some odd reason. Even repeating this, they still did not work - I checked that I had permission (since I have a mac and its a bit touchy).

I had to download all of the files as a zip, unzip the whole thing, and hand pick and drag all the jars I needed out of their respective folders.

Edit: enter image description here you'll see the 'download zip' in the bottom right of the screen grab. That is what I clicked and unzipped for the working jars.



来源:https://stackoverflow.com/questions/25276201/espresso-android-jar-error-in-opening-zip-file-in-android-studio-8-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!