Mike
Mike

Reputation: 6839

Gradle Project Sync Failed on latest android studio

I installed the latest Android studio and am getting a gradle project sync failed when I start a new project:

enter image description here

build.gradel file:

// 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.0.0'

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

allprojects {
    repositories {
        jcenter()
    }
}

When i added:

 compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

I got this error:

enter image description here

Upvotes: 0

Views: 215

Answers (1)

Mohit
Mohit

Reputation: 2628

Add this to your build.gradle.

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

inside android { }

Trageting Android 21 requires JavaVersion 1.7. default is 1.6.

In the case you don't have JDK 7 installed download it from jdk download site

Update

Newer version of Android Studio have built-in OpenJDK 8, So with newer version of Android Studio this error should not exist and You no longer need to download Oracle JDK unless you really want.

Upvotes: 1

Related Questions