Android Studio compile project with Java 8?

Eric

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

ceph3us

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 againsta java 1.8 you need to uae "jack" see https://source.android.com/source/jack.html

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Compile GitHub Project to be used in Android Studio

Android studio does not let me compile project

How to import android project as library and NOT compile it as apk (Android studio 1.0)

Is it possible to compile project on java 8 for target java 6?

Android Studio does not let me compile a specific project

Android Studio. Cannot compile/ build my project after updating

Could not compile Cordova project in Android studio with Cordova plugin

Android studio project cannot compile after adding facebook api

Using Java 8 in android studio

Android Studio, Java 8, and Function

Maven 3.7.0 compile java 8 project encount incompatibility API

Maven project won't compile with Java 8 on OSX

Android Studio: create Java project with no Android dependencies

Android Java Project Converts to Kotlin in Android Studio

In Android Studio how can I configure my project to use Java 8

How to import existing java project into android studio?

install mapbox on java android studio project

Unable to create a java project in android studio

Gradle Android Project with Java 8 module

Loaded "old" Android Studio project - after Studio updates it will no longer open/compile asking for even newer version?

No such property: compile for class: java.lang.String in android studio

How to implement jdoodle API to compile and run java programs in Android Studio?

Is r8 enabled on existing project after updating Android studio?

Getting error in Android Studio 2.1 with java 8

Weird Android Studio error with Java 8

Android Studio use Java 8 instead of 11

Android Studio seems to be stuck at Java 8

Compile android project with a higher sdk

Unable to compile my android project