Reputation: 3627
I am facing issue for Android N layout XML preview. it is showing following message :
"Android N requires the IDE to be running with Java 1.8 or later"
also i install JAVA 1.8 in my OS.
also change the project JDK location with Java 1.8.
but when i see help->about of android studio it is show always 1.7.
how can i change it.?
Upvotes: 13
Views: 96085
Reputation: 5331
As Krishna Meena is mentioning you should change the SDK/JDK Location settings found from within:
File -> Project Structure... then SDK Location and now press on the link Gradle Settings...
Then choose your Gradle JDK to use...
Upvotes: 2
Reputation: 535
just add the tag below, in your build.gradel ( app level file), under android{ } tag,
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
like this,
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.code"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
And now you are good to go.
Upvotes: 0
Reputation: 134
You have to set JAVA_HOME in your operating system.
Windows
Linux
How to set JAVA_HOME in Linux for all users
OSX
What should I set JAVA_HOME to on OSX
Upvotes: 9
Reputation:
I think you are using windows 7/8/10 with 64bits
just install jdk with x86 version No need to reset your environment variable. that will remain same as you have declared.
Upvotes: 1
Reputation: 339
As it is mentioned in the documentation you can add the STUDIO_JDK env var to configure the IDE JDK. In order to access it from your GUI, you can add this line to your ~/.profile file :
launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk<version>.jdk
Upvotes: 1
Reputation: 6429
Go to File -> Project Structure --> SDK Location and check JDK location to set jdk 1.8 or not
See the attached screenshot for more
Upvotes: 23
Reputation: 2571
Android Studio might show the Java Version that it is set to use as 1.7, but your project can still be set to use 1.8.
Firstly add the following to your gradle file (Refer to: Official Android Dev - Java 8 in Android Studio)
defaultConfig {
...
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Secondly go to "File" -> "Project" -> "SDK Location"
Check that the JDK Location is pointing to 1.8 and not 1.7
Running your Android N emulator should now work. Regardless of whether Android Studio itself states it's using 1.7 or 1.8.
Follow the guidelines that are provided on the Android site:
Upvotes: 11