Error running android: Gradle project sync failed.

2019-01-21 04:19发布

问题:

Android Studio (1.2 RC0) keeps telling me Error running android: Gradle project sync failed. Please fix your project and try again. How can I find out what the problem is? Unfortunately the solutions from this SO thread did not help.

回答1:

  1. Goto File -> Invalidate caches / Restart
  2. Shutdown Android Studio
  3. Rename/remove .gradle folder in the user home directory
  4. Restart Android Studio (It will download gradle metadata and data)
  5. Gradle build succeed
  6. Rebuild project. Done.


回答2:

Solution is

  1. Connect your computer to the internet

  2. Click

Sync project with Gradle files

On toolbar

It will automatically sync the gradle.



回答3:

Just ignore the error and try running the project anyway. It will fail, but this time you will get a link in the error description. Clicking the link will trigger the automatic update/download of the outdated/missing component.

In my case, the project failed to launch two times, each time another API/SDK component being the culprit.

In my case I was just trying to launch a sample project I downloaded, having no clue what API level was being targeted or where to look for this information.



回答4:

  1. Download the latest Gradle package distribution for example (gradle-2.11-all.zip).
  2. Extract this zip file in a folder as for example (D://Gradle)
  3. Load your project in Android Studio and go to File->Settings->Gradle. Click on Use local Gradle distribution and point it to the folder where you unzipped the latest Gradle project.
  4. Restart your project


回答5:

Go to

file->settings->build,execution,deployment->gradle.

(and set gradle home path from your directory)



回答6:

I had the same issue yesterday. After opening the "Android SDK Manager", updating all packages and restarting Android Studio, the project compiled again.



回答7:

It is a very common issue and the solution is very easy... Just update the SDK in SDK manager(see full instructions below)

  1. Open Android Studio and go to your SDK Manager(File>Settings>SDK Manager)
  2. Check for (-) icon in front of any package and click on it.
  3. Click OK to start updating the SDK.

Thanks for asking that question :)



回答8:

If no error messages are shown: sometimes the command-line gradle shows them. Just go the the command-line, change to the app directory and type

gradle installDebug

or, if the details are missing

gradle --info installDebug

This can provide additional information how to debug the problem.



回答9:

Goto File -> Invalidate caches / Restart Shutdown Android Studio Rename/remove .gradle folder in the user home directory Restart Android Studio (It will download gradle metadata and data) Gradle build succeed Rebuild project. Done



回答10:

it looks different from one situation to another. for me i did an installation and update a lot of things that the sdk manager said to then i had this problem. all i did was: from file -> Invalidate caches/Restart (a dialog will pop-up) choose Invalidate and restart.

after the restart is done. everything was fixed but i needed to create a new emulator and delete the old one. (android studio 1.3.1) (one professional must edit this to be more understandable) . . . Here everything was fine, but your machines also needs restart because some system files are changed, to sync them we have to restart the system.



回答11:

It took me some time to resolve this.

  • Updated SDK Build-Tool [Didn't help]
  • Updated CMake [Didn't help]
  • Updated Android SDK Platform-Tools [Didn't help]
  • Updated Android SDK Tools [Didn't help]
  • Updated NDK [Problem solved]

There was a reason, I didn't want to update NDK. When all else failed, I updated NDK and that did the trick.



回答12:

If your got timeout, Check Gradle Scripts -> gradle.properties in Android Studio, I found that I do have set a socket proxy in Android Studio settings, but in this gradle.properties file, my proxy became to http, so I just removed this http proxy setting lines, and finally works.



回答13:

I got this problem on Android studio, there in either sync or build square were this link like blue text about this issue, press that button and it download something that fix this problem



回答14:

Resolution is simple. Open the "Android SDK Manager", update all packages and then restart your Android Studio. After that you project should compile without any issues.



回答15:

It could be that you are using gradle in offline mode. To uncheck it go to File > Settings > Gradle, uncheck the Offline Work checkbox, and click Apply Make sure you have internet connection and sync the project again.



回答16:

Apparently, some platforms could be missing. This is how I solved the problem:

Do you see an error message that is shown at the bottom of your Android Studio window? It could be a smaller window on the bottom right also.., which looks like:

Now, Click on that blue link, do as the dialog boxes say (if any)...

That solved the problem. Hope it helps...



回答17:

I ran into the same issue, but then did the following, and my issue was resolved:

  • updated Gradle
  • installed the latest version of Android studio (mine was out of date)

And that solved my problem.

Note: It also helped me to click on the event log, because it has more detailed info about errors. https://developer.android.com/studio/releases/gradle-plugin#updating-plugin also has great info.



回答18:

Download grade files from this url and extract all in a folder:
 https://gradle.org/releases

Open file -> Setting in windows OS or Preferences in mac OS and in "Build, Execution, Deployment"

Click on "Gradle"

Check “Use local cradle distribution” and give that extracted folder path.

Run gradle.bat for Windows OS and gradle file for mac OS in that folder.

Then check “Offline work”.

"your extracted folder path"/gradle-4.10.2/bin/.gradle (for version 4.1.2 you can set your version)

Press OK and enjoy it.



回答19:

Delete "build" folder from project's root folder. Then do "invalidate cache and restart". This will restart your Android Studio and then build the app again, will solve the issue.



回答20:

it was hard to solve but i did it look go to C:\Users(user name)

delete .gradle file its you didn't see it it may be in hidden files so if you use windows 7 right click then click on properties and click on hidden to be not checked

then the file will appear then delete it i hope this works



回答21:

Its because the gradle is not synced because of many reasons.

Go to project folder and remove .gradle folder and start sync. It will work