简体   繁体   中英

Is JDK 1.8 fully supported by Android Studio?

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.

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"

}

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

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.

您可以使用java 1.8但不使用1.8功能,因为Java 1.8中有一些功能现在不受支持。

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:

\n

\n

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.

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM