13

How to fix the following error?

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

Android Studio --> File --> Project Structure --> Modules --> Unresolved reference: JavaVersion.VERSION_1_8

enter image description here

3
  • Are there other options in the dropdown? Also, do you have JDK 8 or later installed? Commented Oct 29, 2018 at 18:51
  • @TheWanderer I found workaround, see below Commented Oct 29, 2018 at 19:15
  • Anyone reported this issue on issuetracker.google.com ? Commented Mar 7, 2019 at 7:47

2 Answers 2

13

I added to the buildscript section of the root build.gradle the ext.java_version variable

buildscript { ... ext.java_version = JavaVersion.VERSION_1_8 ... } 

and changed in the module's build.gradle JavaVersion.VERSION_1_8 to java_version

android { ... compileOptions { sourceCompatibility java_version targetCompatibility java_version } ... } 

Now it's all work fine.

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

I know it's been awhile since this post... I have the Giraffe version of AndroidStudio... I find a "buildTypes" in build.gradle, but not a "buildScript"
0

in my case, i created a new android studio kotlin project and in my build.gradle.kts of the app (a generated file), it said

compileOptions { sourceCompatibility = VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } 

where "VERSION_1_8" on sourceCompatibility did not resolve correctly. I changed it to "JavaVersion.VERSION_1_8" and now it works fine.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.