10

I am trying to build an android app with some dependencies compiled in java 11.

I have configured this in the build.gradle :

android {
  compileOptions {
      sourceCompatibility = 1.11
      targetCompatibility = 1.11
  }
    ...
}

And I have configured my project structure with the java 11 sdk.

I am using this version of the android tool build plugin :

classpath 'com.android.tools.build:gradle:3.5.3'

And this version of gradle :

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

I am also pointing to java 11 for the Gradle JVM.

But when I compile the app, I always get this error :

Execution failed for task ':app:compileDevJavaWithJavac'.
> Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)'.

I do not understand why.

I have checked my JAVA_HOME and my java -version and they both point to 11.

Does anybody has an idea of what is going on ?

Thanks

Naman
  • 27,789
  • 26
  • 218
  • 353
hachiko
  • 121
  • 1
  • 1
  • 6
  • 1
    Please see this: https://stackoverflow.com/a/48114212/2683297 – Gabriel Lidenor Jan 17 '20 at 15:45
  • Not working as well... Now I get this error : ```class file has wrong version 55.0, should be 52.0 Please remove or make sure it appears in the correct subdirectory of the classpath.``` – hachiko Jan 17 '20 at 16:21
  • Do you compile inside Android Studio or on a stand-alone command-line? Android Studio contains an integrated Java 8 JDK which is used by default. – Robert Jan 18 '20 at 12:21
  • I'm using IntelliJ and the stand-alone Gradle inside the project. IntelliJ is delegating the build to Gradle. And I have changed the Gradle JVM to use java 11. – hachiko Jan 20 '20 at 07:01

2 Answers2

6

Try like this :

compileOptions {
    targetCompatibility JavaVersion.VERSION_11
    sourceCompatibility JavaVersion.VERSION_11
}
dgp
  • 683
  • 3
  • 13
-3

If using Kotlin in your module, your build.gradle file should be set as so:

android {
 ...
  compileOptions {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
  }

  kotlinOptions {
    jvmTarget = "11"
  }
}
mvbrenes
  • 517
  • 5
  • 9