3

I'm trying to compile a project using java 8.

I've set the correct jdk as shown in the image:

JDK location

Also changed the target version:

Target version

But I still got the error: compileSdkVersion 'android-24' requires JDK 1.8 or later to compile.

Where am I wrong?

EDIT: I'm on Ubuntu 12.04

3
  • The path to your jdk should be more specific. In Mac I have jdk1.8.0_92.jdk/Contents/Home Commented Jul 27, 2016 at 15:57
  • @JuanCruzSoler my path is correct, because I'm running Ubuntu Commented Jul 27, 2016 at 16:03
  • Possible duplicate of Is it possible to use Java 8 for Android development? Commented Jun 14, 2019 at 14:27

2 Answers 2

8

When goes to JDK setting you can:

add in "android app" module build.gradle

compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } 

setup sdk path in gradle.properties

org.gradle.java.home=/path_to_java_sdk_8/jdk1.8 

check also .idea/modules/compiler.xml against 1.7/1.8

<?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="CompilerConfiguration"> ... <bytecodeTargetLevel target="1.8"> <module name="app" target="1.7" /> </bytecodeTargetLevel> </component> 

and misc.xml

<?xml version="1.0" encoding="UTF-8"?> <project version="4"> .... <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/build/classes" /> </component> <component name="ProjectType"> <option name="id" value="Android" /> </component> </project> 

BTW: if you want compile against java 1.8 you need to use "jack" see https://source.android.com/source/jack.html

Sign up to request clarification or add additional context in comments.

1 Comment

Setting org.gradle.java.home=/path_to_java_sdk_8/jdk1.8 did the trick! Thanks!
3
android { compileSdkVersion 28 buildToolsVersion = '28.0.3' defaultConfig { applicationId "your package name" minSdkVersion 21 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.