25

I just downloaded JDK 1.8.0_51 from my previous JDK 1.8.0_33 because i was having issues. There being some workaround to use Jdk 8 with Android, I was just wondering has Google already added a full support to the JDK in Android studio ? or should I just use JDK 1.7? advice will be highly appreciated.

Madona wambua
  • 1,408
  • 1
  • 21
  • 37
  • 2
    I have Java 8 only and Android Studio here. No problem so far. But don't use (When developing Android App) Java 8's feature like Lambda. It will not work yet. – Glenn Jul 21 '15 at 11:54

8 Answers8

16

you can now use java8 with android

add this lines in you build.gradle file

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

refer this doc http://developer.android.com/intl/es/preview/j8-jack.html

Make sure to enable Jack as well with:

android {
  //...

  defaultConfig {
  //...

  // Required to use Java 8.
  jackOptions {
    enabled true
  }

}

Additionally, you will need to be using version 24 or greater of the Android SDK Build Tools:

android {
  //...

  buildToolsVersion "25.0.2"

}
Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
Rax
  • 1,347
  • 3
  • 20
  • 27
10

You should just use JDK 1.7. There are some features in JDK 8 that are not yet supported.

d0nut
  • 2,835
  • 1
  • 18
  • 23
  • 1
    @JoshPinter You can use JDK 8 but, unless your android app targets SDK 23 and higher, there is no need to use JDK 8. Java 8 _can_ be used if you enable 'Jack and Jill' but, like I said, that requires a _minimum_ target of 23. – d0nut Mar 01 '17 at 19:29
  • Thanks. I went down that route and ran into issues with Jack and Jill causing my app to crash. Had to increase the heap size and a bunch of other things, too. It was decidedly not worth it. :) – Joshua Pinter Mar 01 '17 at 22:58
  • @JoshPinter What I recommend, if you want to use something a little more modern, is just write your application in Kotlin. It is 100% completely interoperable with Java and gives you things like lambdas which make writing the application a more pleasant experience. The language itself is a lot more like Swift than Java and is used by JetBrains to build their IDEs from my understanding. Very stable. – d0nut Mar 02 '17 at 02:39
  • 1
    Great, thanks for the tip. I've read and watched a lot about Kotlin. I'm mostly developing in React Native these days but if end up doing a lot of native work, I'll take a look at it. – Joshua Pinter Mar 02 '17 at 02:43
6

Using JDK 1.8 is OK and nothing will bother you except Android Studio may often provide runtime check for you to suggest you using JDK 1.8's feature like lambda. But you can go to Settings->Editor->Inspections->Java language level issues/migration aids and close what you want.

ywwynm
  • 11,573
  • 7
  • 37
  • 53
5

You can use java 1.8 but dont use 1.8 feature because there are some feature in Java 1.8 which are not supported by now.

Shakeeb Ayaz
  • 6,200
  • 6
  • 45
  • 64
4

If you previously used JACK options, which are deprecated from Android Studio 3.0.0, migrating and using the supported Java 8 language features would be as simple as removing:

jackOptions { enabled true }

from the app's build.gradle file and keepping the configuration as follows:

android {
  ...
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

For details follow this link.

Kreshnik
  • 2,661
  • 5
  • 31
  • 39
2

Use Java 1.7 or Java 1.6 I had problems by my self with Android 4 and Java 7 so I used 1.6 and all problems where gone.

I think you will got less problems when you use 1.7 instead of 1.8

0

I started getting this error after java update to 1.8

Error:Execution failed for task ':app:processDebugResources'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\whatever\AppData\Local\Android\sdk\build-tools\23.0.1\aapt.exe'' finished with non-zero exit value 1

0

Actually you get all sorts of crazy Gradle errors when trying to build Android Studio projects with Java 8, like

2016-04-10 17:50:49,401 [1624477] WARN - nal.AbstractExternalSystemTask - Gradle 2.10 requires Java 6 or later to run. Your build is currently configured to use Java 5. com.intellij.openapi.externalSystem.model.ExternalSystemException: Gradle 2.10 requires Java 6 or later to run. Your build is currently configured to use Java 5.

As soon as I switched the default JDK to Java 7 it works fine. Looks like running Android Studio itself with Java SE 8 is tolerated, but building Android apps via Gradle with it only works well with Java 7.

Werner Keil
  • 592
  • 5
  • 12