Android – ‘Gradle project Sync failed. Basic functionality will not work properly.’ How to solve this

androidgradle

All of my old projects have been working fine. Then one day, whenever I make a new project, I get :

enter image description here

And in the lower window, Messages Gradle Synch :

enter image description here

Some of the solutions I tried :

How to use the latest gradle version in Android Studio

In gradle-wrapper.properties I already have the up to date version :

distributionUrl=http\://services.gradle.org/distributions/gradle-2.12-all.zip

As suggested in another post, I believe I have the latest version of gradle plugin. In File/Project Structure/Project I have :

enter image description here

Another post on SO said to right click on my Java directory and select from the menu, 'Mark Directory as Source'. But this option does not even appear in my menu. My version of Android Studio is AS 2.1 Preview 5.

I can't select my java folder in blue, as it should be (marked as source) and my MainActivity java file has a funny red symbol. I seem unable to make it a java class file :

enter image description here

Any idea how to solve this problem on this buggy platform?

Best Answer

This answer helped :

Android Studio 2.0 - Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to

Basically, in my gradle-wrapper.properties I put this line :

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

// or whatever latest version here : https://services.gradle.org/distributions

In my build.gradle (Project:YourApp) file I put :

classpath 'com.android.tools.build:gradle:2.1.2' //or whatever latest version here : https://bintray.com/android/android-tools/com.android.tools.build.gradle

Then I cleaned my project, rebuilt and now it seems to work ok.