Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle error : unable to open zip file

When I open Project it will give error:

Error:Failed to open zip file. Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)

I tried this: Error:Failed to open zip file. Gradle dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

but not working for me.

this is my build.gradle file:

apply plugin: 'com.android.application'

android {
     compileSdkVersion 26
     buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.example.web"
        minSdkVersion 18
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.android.support:appcompat-v7:26.0.1'
      compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
allprojects {
repositories {
    jcenter()
    maven {
        url 'https://maven.google.com'
    }
    maven { url "https://jitpack.io" }

}

Top Level Build File (Project Level)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()

        flatDir {
            dirs "${rootDir}/libs"
        }
    }

}

task clean(type: Delete) {
    delete rootProject.buildDir
}
like image 575
Learning Always Avatar asked Oct 17 '22 15:10

Learning Always


2 Answers

I also faced same issue sometime ago, I found simple workaround for it.

File ->Invalidate Caches/ Restart -> Select Invalidate and Restart option.

It will clear all local history and restart automatically. All necessary files will be downloaded automatically.

like image 190
Jitesh Mohite Avatar answered Oct 21 '22 04:10

Jitesh Mohite


According to the solution here:

  • Close Android Studio.

  • Download Gradle 3.3 binary from https://services.gradle.org/distributions/gradle-3.3-bin.zip

  • Extract the downloaded zip file to the gradle folder:

      C:\Users\user-name\.gradle\wrapper\dists\
    
  • Now open the Android Studio, go to File -> Settings -> Build, Execution, Deployment -> Gradle and set Gradle Home to the folder gradle-3.3 and SYNC.

OR

  • Close Android Studio.

  • And delete all the files under this directory:

      C:\Users\user-name\.gradle\wrapper\dists\
    
  • Now open the Android Studio and the necessary files will be downloaded automatically.

like image 22
youpilat13 Avatar answered Oct 21 '22 04:10

youpilat13