Gradle project refresh failed in Android Studio 1.

2019-05-12 00:41发布

问题:

I created sample project on the fresh installation of the Android Studio v 1.2.1.1 and i faced with this error message:

Gradle project refresh failed in Android Studio 1.2.1.1 

See image below:

So i tried to find any solution on the Google and i checked

gradle.properties file

where is:

dependencies {
        classpath 'com.android.tools.build:gradle:1.2.2'

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

After that i tried to update all SDK libraries using SDK manager

And after that i tried to find issue in settings (see image)

But everything without success. Because in the error description is nothing i don't know what can be wrong and what to repair.

Any idea please?

Many thanks for any help.

Note: Compilaton using Cordova (which is using Gradle too) is without problems and app is compiled.

回答1:

For anyone who is struggling with this error, here is my solution:

Step 1) Click in "Android Studio" (upper bar) -> "Preferences" -> "Build, Execution, Deployment" -> "Build Tools" -> "Gradle"

And select "Use local gradle distribution" and find the path for your Gradle file (eg. /Applications/Android Studio.app/Contents/gradle/gradle-2.8)

Step 2) Click in "File" (upper bar) -> "Project Structure" -> Select "app" in the "Modules" section. Then, make sure you have set the Compiler SDK Version and Build Tools Version

Step 3) Open your project -> Open "build.gradle" file and then remove the following lines:

android {
    compileSdkVersion XX
    buildToolsVersion 'XX.X.X'
}

Step 4) Click in "Sync Project with Gradle Files" button.

Full instructions here



回答2:

This Answer helped me solve my gradle sync problem. https://stackoverflow.com/a/27784297/1157720

Remove .gradle from home directory.



回答3:

I tried multiple solutions for this. Finally, following worked for me.

  1. Close Android Studio
  2. Delete (or better move them somewhere to have a backup) .gradle from following path :

Android Studio > File(Menu bar) > Settings > Build, Execution, Deployment > Build Tools > Gradle > (In the right pane) Service Directory Path: "Some Path" \ .gradle

Go to "Some Path" and Delete or take back up of .gradle folder .

  1. Start Android Studio again and rebuild/refresh. This will again create the .gradle folder

Cheers :)



回答4:

This might be too late to answer. But this may help someone.

In my case there was problem of JDK path.

I just set proper JDK path for Android Studio 2.1



回答5:

Set chmod to 775 on .gradle dir in the home directory helped to me solved it out.



回答6:

File -> Invalidate Caches / Restart -> Invalidate and Restart worked for me.



回答7:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies
    {
        classpath 'com.android.tools.build:gradle:2.3.0'
    }
}
allprojects 
{
    repositories 
    {
        mavenCentral()
    }
}