Android 1.5 Gradle Sync never completes

2019-04-09 16:03发布

I recently upgraded to Android Studio 1.5. However, after update, Gradle gets stuck at "Refreshing [project] Gradle Project" and never stops.

Previous version of Android Studio worked just fine.

How do I solve this?

I am on an Ubuntu 15.10 64bit machine.

Edit:
So far, I have tried deleting Android Studio from /opt and downloading the latest version. Didnt help.

I also tried removing the ~/.AndroidStudio1.5 directory. To no avail.

This is in my "Event Log"

Gradle sync started
NullPointerException: null

4条回答
▲ chillily
2楼-- · 2019-04-09 16:25

go to Preferences > Build, Execution > Build Tools > Gradle and change the Gradle Home path. I had to change mine because it had the wrong value, it was /Applications/Android Studio.app/Contents/gradle/gradle-2.4 and I changed it to /Applications/Android Studio.app/Contents/gradle/gradle-2.8

查看更多
孤傲高冷的网名
3楼-- · 2019-04-09 16:29

In your Android Project change gradle-wrapper.properties file, which is in *project/gradle/wrapper:

From:

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

To:

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

And also change the project build.gradle like below:

 dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
}
查看更多
走好不送
4楼-- · 2019-04-09 16:33

In your build.gradle for the project, update your classpath to gradle 1.5.0

Example:

// 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:1.5.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-04-09 16:38

I had the same problem. My JAVA_HOME wasn't set to the right directory. Ehsun Mehranvaris answer is more like a hack, than a solution. I tried to built the android project per terminal with ./gradlew and it told me JAVA_HOME wasn't set correctly.

To get the path of your java enter in terminal:

readlink -f $(which java)

Set your JAVA_HOME like this in terminal:

export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre

After that, I switched to the android project directory in the terminal and did run this command:

./gradlew

This will build your project and in my case it downloaded the latest gradle 2.8 package. Android Studio might download the package itself, if you set the JAVA_HOME correctly. Didn't try that.

Now you can use the default gradle wrapper from Android Studio and don't need to edit any property file manually. You find that at Preferences > Build, Execution > Build Tools > Gradle

查看更多
登录 后发表回答