Android Studio - Gradle build fails after setting target compatibility to JDK 1.8


I'm having issue with gradle after setting the target compatibility (under File -> Project structure in Android Studio) to 1.8.



I've tried to delete the .gradle folder under C:Usersprofile, reboot PC and relaunch Android Studio (which has downloaded all the gradle's stuff again), but nothing seemed to work.
I've also tried to delete the .gradle folder in my project's root directory.



The problem occurs only with target JDK set to 1.8; if I set that to 1.7 (and if I remove all the JDK 8 stuff, like lambdas) the build runs successfully.



These are the logs:





I've included this lines in my gradle file but still it does not build successfully.



You should make sure you're not using any non-supported Java 8 APIs or features depending on your minSdkVersion.



The complete list can be found here.



Also make sure you also set on your gradle build, the sourceCompatility to Java 8.



I'll post an answer, since I don't found this solution anywhere I've looked, so it could be useful to someone else.



The problem was that File -> Project structure -> JDK location on Android Studio pointed to a JDK 9. I've downloaded JDK 8 and I've changed the pointed directory to that which contains JDK 8 and now gradle can build with Java 8 target.



I guess I'll never know why gradle needs JDK 8 to build for target 1.8, while it can build for target 1.7 using JDK 9...






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

佛陀 (漫畫)

Đế Bá

文学批评