Android N requires the IDE to be running with Java 1.8 or later?
Solution 1
Set JDK_HOME
and JAVA_HOME
environment variables, in my case C:\Program Files\Java\jdk1.8.0_60
.
Check Java version in Help > About
. It should show the JRE version you just set.
That is it, now you can preview your layout in N
.
Solution 2
I got the same error you describe but on OS X. I know this may not solve your problem (because I don't know the equivalent for Windows), but since this is not OS specific I am leaving the solution for any OS X fellow out there.
Edit the file /Applications/Android\ Studio.app/Contents/Info.plist
, and remove the 1.6 version (in my case), you may place 1.6+, 1.7+ or 1.8, whichever you prefer. Mine ended up like this
...
<key>JVMVersion</key>
<string>1.7+</string>
...
Be aware there's an incompatibility with drag and drop with java versions 1.8_60 to 1.8_75 (IDEA-146691) which the IDE will report once you successfully change the version.
For non Terminal Users
- Find your
Android Studio.app
file. If it's in the dock you can right click it and chooseOptions > Show in Finder
. - Right click it and choose
Show package content
. - Navigate to the mentioned file (
Contents/Info.plist
). - Edit the file with your favorite text editor.
Solution 3
Click on the letter N, next to the android icon in the Preview window and select API level 23 or lower. That should solve it.
Solution 4
For Mac users with this issue (I'm running OS X 10.11.5 and Android Studio 2.1.2), here's how you can solve it:
Currently, the Mac version of Android Studio is run with Java 6 (not necessarily the same as the JDK version for the app), because Java 6 has better font rendering than Java 7 & 8, and that's apparently more important than rendering your layout.
First of all, make sure you have JDK 8 installed.
Then run the following commands:
$ export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk
$ open /Applications/Android\ Studio.app/
You may need to change the 91
in jdk1.8.0_91.jdk
to a different version. You can see which JDK versions you have with:
$ ls /Library/Java/JavaVirtualMachines/
Unfortunately, this method requires opening the app from the terminal, but you could always create a script for it.
Edit: And if you really don't want to open it from the terminal:
- Create an AppleScript with contents:
do shell script "export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk; open /Applications/Android\\ Studio.app/"
- File > Save Choose file format Application. Save it somewhere.
- If you want to change the icon, see here.
- Drag the app to your launchpad if you like.
Solution 5
I met the same issue.
I installed jdk1.6,jdk1.7,jdk1.8, and deployed Studio as what you did.
My solution is uninstall jdk1.6 and jdk1.7, only leave jdk1.8
sudo rm -rf ${path to jdk1.6}
sudo rm -rf ${path to jdk1.7}
That's all.
Related videos on Youtube
![mihirjoshi](https://i.stack.imgur.com/6KTf1.jpg?s=256&g=1)
mihirjoshi
I will make you an app you cant refuse. I am nerdier than 98% of all people. Are you a nerd? Click here to take the Nerd Test, get geeky images and jokes, and talk on the nerd forum! http://www.nerdtests.com/images/ft/nq/21991e3bef.gif http://stackrating.com/badge/1919641
Updated on April 03, 2020Comments
-
mihirjoshi about 4 years
My
XML
layout is not rendering with this error message. I am already using Java 8.Also using latest build tools in Gradle.
android { compileSdkVersion 'android-N' buildToolsVersion 24.0.0 rc1 ... }
XML Error -
-
CommonsWare over 8 yearsThere are all sorts of rendering problems with Android Studio. I suggest that you provide a minimal reproducible example. In this case, that would include the layout file and the specific error.
-
mihirjoshi over 8 years@CommonsWare I updated the XML error image. Install a supported JDK redirected me to set up steps which I already did.
-
Phyrum Tea over 8 yearsI had to change to buildToolsVersion '24.0.0 rc1', the documentation was missing the quotes.
-
mihirjoshi over 8 years@PhyrumTea Didn't make the error go away.
-
Phyrum Tea over 8 yearsThe error message suggest, that android studio was started with other (wrong) JDK. What is in the about box? Help->About
-
mihirjoshi over 8 yearsFinally, when I tried to build and run the project, it failed with
Directory cannot have its readable permission cleared for everybody
. Apparently it's a known bug and google is working on it. -
Suragch almost 8 years
-
-
mihirjoshi over 8 yearsBut I want to preview in N not in API 23.
-
santhyago over 8 yearsThis will change the virtual machine where Android Studio runs on. In my OSX, original value was: <key>JVMVersion</key> <string>1.6*,1.7+,1.8</string> And the new value is: <key>JVMVersion</key> <string>1.8</string>
-
Kotik_o about 8 yearsIt works! Thanks for this solution. The question is: Why Google wants that his developers wasted his time on this issues?
-
Totalys about 8 yearsThanks for solving google´s lack of documentation :). I wonder why this instruction is not here: developer.android.com/intl/pt-br/preview/setup-sdk.html#java8 (This is the link displayed at android studio).
-
Micro about 8 yearsWorks great!! Sadly, when updating Android Studio (which I just did to newest version), it resets the Info.plist file so I have to repeat the steps again to change my JVMVersion:
<key>JVMVersion</key> <string>1.8</string>
So annoying Android Studio! -
The_Martian about 8 yearsI did what you said but when I do help->about it still points to my old jdk. Why is that?
-
Zapnologica about 8 yearsI have JRE: 1.8 (in about). However I cant build apps targeting v24.
> compileSdkVersion 'android-24' requires JDK 1.8 or later to compile.
-
terencey about 8 years@The_Martian you need to restart your computer.
-
lopez.mikhael about 8 yearsOn Mac Os I remove my old jdk version. After that, Android Studio pick the last version
-
jmnwong about 8 yearsAndroid Studio 2.2 uses <string>1.8*,1.8+</string>.
-
Mike about 8 yearsMine still says "partially installed" after reinstalling.
-
Micro almost 8 yearsis that safe to do
-
youngwind almost 8 years@MicroR If you the other softwares haven't depended on jdk1.6 and jdk1.7, I think it is safe.
-
mythicalcoder almost 8 yearsMine too "partially installed" after reinstalling. @Andrew did you find any solution afterwards ?
-
mythicalcoder almost 8 yearsI have set the JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home" Should STUDIO_SDK also be "/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home" ?
-
Mike almost 8 years@Maven for me, turned out that my problem was that I wasn't selecting the correct build variant when I tried building the app.
-
Sergio A Guzmán almost 8 years@Maven theoretically you may set STUDIO_SDK variable which will be SDK path to run Android Studio (as said in Studio's config params tools.android.com/tech-docs/configuration). However, in my case I didn't setted that variable and IDE is running as expected.
-
mythicalcoder almost 8 yearsYou are right. I tried different things. It was indeed the problem of 1.8 not linked properly. This solved it stackoverflow.com/a/35935433/2369867. Thanks.
-
Nishant Srivastava almost 8 yearsSo the way it worked for me was that , in my OSX, original value was: <key>JVMVersion</key> <string>1.6*,1.7+,1.8</string> which I completely replaced with <key>JVMVersion</key> <string>1.8*,1.8+</string>.
-
Showpath almost 8 yearsThis solution fixed the problem for me. This way of uninstalling is safe and is the one recommended by Oracle (docs.oracle.com/javase/8/docs/technotes/guides/install/…)
-
Saima almost 8 yearsI experienced the same issue on my mac. lowering the API level from 24 to 23 worked for me.
-
Terix almost 8 yearsMy system was missing all the JAVAx_HOME variables, I had jdk 1.6, 1.7, 1.8 installed, but I still had only 1.6 on my JAVA_HOME. Who is supposed to create those variables? Shouldn't Java do the job? Btw that fixed everything
-
Pavneet_Singh almost 8 yearsnot an answer , please follow the answer marked as right
-
Dustin Butler almost 8 yearsThis worked for me on Mac! Thank you! I am on OS X El Capitan 10.11
-
Daniele almost 8 yearswhen I try to run the script I get:
error "sh: /usr/local/bin/studio: No such file or directory" number 127
any way to fix it? when I run it from terminal it works perfectly -
wumbo almost 8 years@Daniele Sorry, I forgot that I created another shell script for that. The AppleScript should have the same commands as above. See my updated answer.
-
0xC0DED00D almost 8 yearsDo not do this, it'll mess with Android Studio updates. Just change STUDIO_JDK environment path.
-
enadun almost 8 yearsThis is not an answer. This is just ignoring the problem environment.
-
Milon almost 8 yearshow to open this file? I am using Mac but could not find that location.
-
arango_86 over 7 yearsNicely done. Yes, It solved my problem. Thank you. :)
-
zgc7009 over 7 years@lopez.mikhael that actually is the only thing that worked for me in the end. I changed every possible setting I could find, configured everything exactly how I was supposed to, kept getting the error. In the end, I moved the older jdk directories to a subdirectory I named old_jdks in the JavaVirtualMachine folder. Everything works great now.