Android Studio: Re-download dependencies and sync

2019-01-09 14:36发布

I downloaded an open source game "ChaseWhisplyProject" source code from Github.

I imported the project in my Android Studio (Version 1.5.1).

It shows following error message:

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)
Re-download dependencies and sync project (requires network)

I changed all the dependency versions to latest one bu still it is showing the same message.

It has two modules under the main project 1) BaseGameUtils & 2)ChaseWhisply. The above modules are not shown in bold letters (I think it should be shown in bold letters like module "app").

Following are the gradle files.

1) Root Gradle:

// Top-level build file where you can add configuration options common to         all sub-projects/modules.
allprojects {
    repositories {
        jcenter()
    }

}

2) BaseGameUtils Module Gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
}

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

dependencies {
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.google.android.gms:play-services:8.4.0'
}

3) ChaseWhisply Module Gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}
apply plugin: 'com.android.application'

dependencies {
    compile 'com.android.support:gridlayout-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.nineoldandroids:library:2.4.0'
    compile project(':BaseGameUtils')
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    lintOptions {
        // TODO fix and remove !
        disable 'MissingTranslation', 'DuplicateIds', 'ExtraTranslation'
    }

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 22
        versionName "0.3.6"
    }
}

4) Settings.gradle

include ':ChaseWhisply', ':BaseGameUtils'

What is wrong over here? Please help.

9条回答
forever°为你锁心
2楼-- · 2019-01-09 15:12

change the gradle-wraper-properties distributionUrl to your local downloaded gradle such as

distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip

查看更多
霸刀☆藐视天下
3楼-- · 2019-01-09 15:14

Clean Project is a way to go. After you clean project, make sure you rebuild it. Usually it solves the gradle issues for me.

查看更多
乱世女痞
4楼-- · 2019-01-09 15:22

May be incompatible with Gradle and maven version delete project dir/gradle/wrapper put a right version gradle into it run again

查看更多
太酷不给撩
5楼-- · 2019-01-09 15:23

It basically means that the gradle zip file in the cache folder is corrupted, if you don't want to change the version like the up-voted answer then you must delete the folder for your gradle version you're using for this project from the below path.

Then just retry the sync and android studio will download it again

C:\Users\ [user here]  \.gradle\wrapper\dists

ex: if you're using 3.3 for this project you'd be deleting the folder

C:\Users\[user here]\.gradle\wrapper\dists\gradle-3.3-all
查看更多
爱情/是我丢掉的垃圾
6楼-- · 2019-01-09 15:25

While importing a libGDX project I got the same message from Android Studio 2.2.

Went to File->Project Structure then selected Project and set

Gradle version

and

Android Plugin Version

to values identical to another project I had recently created with Android Studio 2.2 and updated SDK. Could then sync gradle. Did Build->Build Clean with no issues. Then did Run->Clean and Rerun and project ran fine.

Hope this helps.

查看更多
够拽才男人
7楼-- · 2019-01-09 15:25

I face the same problem and I search for it and found a best solution and i works for me:

  1. Manually download Gradle 3.3 binary (direct link: https://services.gradle.org/distributions/gradle-3.3-bin.zip)

  2. Open your android studio root directory, and extract the zip to the gradle folder (for example: program files/android-studio/gradle/gradle-3.3)

  3. Open Android Studio, go to File->Settings-> (Build, Exectution, Deployment) >Gradle and set "Gradle home" to point your new gradle-3.3 folder.

  4. Apply and sync.

查看更多
登录 后发表回答