简体   繁体   中英

Jdk version automatically resets to 1.7 in android studio

I installed Android Studio and i have both Jdk 1.7 as well as 1.8. When I executed the app , it gave me an error that it needs to be run with Jdk 1.8.I wen to File>> project structure and changed the path for jdk versio to jdk 1.8 but when I click OK the gradle sync starts with jdk 1.7 . Now when I open the project structure again, JDk version is reset to 1.7 again.

My JAVA_HOME system variable is set to the jdk 1.8 path. I uninstalled the Android Studio and reinstalled it, but nothing worked.

In your build.gradle also include the compileOptions tag to force JDK 1.8.

You will need to enable the Jack compiler as well to take advantage of Java 8 features.

android {
  ...
  defaultConfig {
    ...
    jackOptions {
      enabled true
    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

See Google's page on Java 8 features available on Android here: https://developer.android.com/preview/j8-jack.html

Also, keep in mind that certain features are not support under Java 8 with the Jack compiler. One of the biggest (for me at least) is the Transform API with annotation processors. If you or a library you like uses the Transform API, you can disable Jack, and use a library to get some Java 8 features anyway, like Retrolambda.

See here for details on RetroLambda: https://github.com/evant/gradle-retrolambda

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