118

My XML layout is not rendering with this error message. I am already using Java 8.

enter image description here

Also using latest build tools in Gradle.

android {
    compileSdkVersion 'android-N'
    buildToolsVersion 24.0.0 rc1
    ...
}

XML Error -

enter image description here

Jonik
  • 80,077
  • 70
  • 264
  • 372
mihirjoshi
  • 12,161
  • 7
  • 47
  • 78
  • 2
    There are all sorts of rendering problems with Android Studio. I suggest that you provide a [mcve]. In this case, that would include the layout file and the specific error. – CommonsWare Mar 10 '16 at 22:26
  • @CommonsWare I updated the XML error image. [Install a supported JDK](https://developer.android.com/preview/setup-sdk.html#java8) redirected me to set up steps which I already did. – mihirjoshi Mar 10 '16 at 22:31
  • 1
    I had to change to buildToolsVersion '24.0.0 rc1', the documentation was missing the quotes. – Phyrum Tea Mar 10 '16 at 22:47
  • @PhyrumTea Didn't make the error go away. – mihirjoshi Mar 10 '16 at 22:58
  • The error message suggest, that android studio was started with other (wrong) JDK. What is in the about box? Help->About – Phyrum Tea Mar 10 '16 at 23:03
  • 1
    Finally, 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](https://code.google.com/p/android/issues/detail?id=202973) and google is working on it. – mihirjoshi Mar 10 '16 at 23:13
  • See also [Android Nougat requires the IDE to be running with Java 1.8 or later](http://stackoverflow.com/questions/39240533/android-nougat-requires-the-ide-to-be-running-with-java-1-8-or-later). – Suragch Sep 07 '16 at 02:26

17 Answers17

187

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

  1. Find your Android Studio.app file. If it's in the dock you can right click it and choose Options > Show in Finder.
  2. Right click it and choose Show package content.
  3. Navigate to the mentioned file (Contents/Info.plist).
  4. Edit the file with your favorite text editor.
LaloLoop
  • 2,143
  • 3
  • 12
  • 18
  • 11
    This will change the virtual machine where Android Studio runs on. In my OSX, original value was: JVMVersion 1.6*,1.7+,1.8 And the new value is: JVMVersion 1.8 – santhyago Mar 14 '16 at 20:33
  • 8
    It works! Thanks for this solution. The question is: Why Google wants that his developers wasted his time on this issues? – Kotik_o Apr 15 '16 at 17:24
  • 3
    Thanks for solving google´s lack of documentation :). I wonder why this instruction is not here: https://developer.android.com/intl/pt-br/preview/setup-sdk.html#java8 (This is the link displayed at android studio). – Totalys May 03 '16 at 16:25
  • 7
    Works 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: `JVMVersion 1.8` So annoying Android Studio! – Micro May 12 '16 at 01:07
  • 3
    Android Studio 2.2 uses 1.8*,1.8+. – jmnwong Jun 22 '16 at 15:27
  • 1
    So the way it worked for me was that , in my OSX, original value was: JVMVersion 1.6*,1.7+,1.8 which I completely replaced with JVMVersion 1.8*,1.8+. – Nishant Srivastava Jul 21 '16 at 12:56
  • This worked for me on Mac! Thank you! I am on OS X El Capitan 10.11 – Dustin Butler Aug 22 '16 at 02:05
  • Do not do this, it'll mess with Android Studio updates. Just change STUDIO_JDK environment path. – 0xC0DED00D Sep 11 '16 at 11:16
  • how to open this file? I am using Mac but could not find that location. – Milon Sep 15 '16 at 09:36
147

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.

First row of icons in the rpeview window

Ian
  • 2,024
  • 2
  • 12
  • 12
63

Set JDK_HOME and JAVA_HOME environment variables, in my case C:\Program Files\Java\jdk1.8.0_60.

enter image description here

Check Java version in Help > About. It should show the JRE version you just set.

enter image description here

That is it, now you can preview your layout in N.

mihirjoshi
  • 12,161
  • 7
  • 47
  • 78
  • 1
    I did what you said but when I do help->about it still points to my old jdk. Why is that? – The_Martian May 17 '16 at 09:58
  • 1
    I have JRE: 1.8 (in about). However I cant build apps targeting v24. `> compileSdkVersion 'android-24' requires JDK 1.8 or later to compile.` – Zapnologica Jun 16 '16 at 20:06
  • 1
    @The_Martian you need to restart your computer. – terencey Jun 19 '16 at 08:42
  • 1
    On Mac Os I remove my old jdk version. After that, Android Studio pick the last version – lopez.mikhael Jun 20 '16 at 12:14
  • My 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 – Terix Aug 07 '16 at 06:53
  • 1
    @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. – zgc7009 Mar 30 '17 at 01:29
27

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.

More info

Edit: And if you really don't want to open it from the terminal:

  1. Create an AppleScript with contents: do shell script "export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk; open /Applications/Android\\ Studio.app/"
  2. File > Save Choose file format Application. Save it somewhere.
  3. If you want to change the icon, see here.
  4. Drag the app to your launchpad if you like.
wumbo
  • 746
  • 9
  • 21
  • when 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 – Daniele Aug 23 '16 at 19:43
  • @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. – wumbo Aug 24 '16 at 02:32
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.

youngwind
  • 475
  • 4
  • 5
  • is that safe to do – Micro Jul 04 '16 at 15:44
  • @MicroR If you the other softwares haven't depended on jdk1.6 and jdk1.7, I think it is safe. – youngwind Jul 05 '16 at 05:37
  • This solution fixed the problem for me. This way of uninstalling is safe and is the one recommended by Oracle (https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html) – Showpath Jul 27 '16 at 09:34
2

I'm using Ubuntu 14.04 and I was facing a similar error, with the difference I don't have NDK. My solution was, after setting up Java 8 in project definition, reboot Android Studio, no more.

Check system Java version, in console "java -version", output should say something like this

java version "1.8.0_91"
  • I 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" ? – mythicalcoder Jul 17 '16 at 11:41
  • @Maven theoretically you may set STUDIO_SDK variable which will be SDK path to run Android Studio (as said in Studio's config params http://tools.android.com/tech-docs/configuration). However, in my case I didn't setted that variable and IDE is running as expected. – Sergio A Guzmán Jul 18 '16 at 04:23
  • You are right. I tried different things. It was indeed the problem of 1.8 not linked properly. This solved it http://stackoverflow.com/a/35935433/2369867. Thanks. – mythicalcoder Jul 18 '16 at 05:15
2

Had the same problem with Ubunutu. The problem was not running the IDE with Java8.

I fixed it with updating the default java program of the OS, using:

sudo update-alternatives --config java

And choosing the relevant Java8 path.

danny11
  • 483
  • 1
  • 5
  • 12
1

From the docs: https://developer.android.com/studio/intro/studio-config.html#file_location

STUDIO_JDK: set the JDK with which to run Studio

I prefer using the STUDIO_JDK variable and leave other default java home variables alone.

Nublodeveloper
  • 1,301
  • 13
  • 20
1

I faced the problem "Android N requires the IDE to be running with Java 1.8 or later." The error kept showing up in spite of setting C:\Program Files\Java\jdk1.8.0_92 as the project's JDK in File > Project Structure.

I solved it by updating JAVA_HOME in my environment variables from C:\Program Files\Java\jdk1.7.0_67 to C:\Program Files\Java\jdk1.8.0_92. When I did that and restarted Android Studio, the design mode became available.

OS: Windows 10

Android Studio: 2.1.2

Maksim Dmitriev
  • 5,985
  • 12
  • 73
  • 138
1

I have solved it in these way.(AS+MAC OX El Capitan)

  1. Updating SDK Tools>Android SDK platform tools
  2. Go to Help>Edit Custom Properties> A dialog will prompt(press yes) then write

    JVMVersion=1.8 
    

Then close Android Studio fully and reload the project

Milon
  • 2,221
  • 23
  • 27
0

My issue was that the Android N was "partially installed".

My solution was to go to - Preferences/Appearances and Behavior/System Settings/Android SDK and check the Status. If it's "partially installed" then you have to uninstall then reinstall. (Uncheck the checkbox and hit apply; it will uninstall; then you can check the box and install it again) Worked for me. If you go to lower version(like 23) then you have to change the buildToolsVersion variable to "23.0.0" in the build.gradle.

tiborK
  • 385
  • 1
  • 6
0

I was facing the same problem recently. Try changing the API preview level to 23 or lower. That worked for me.

0

I had faced the same problem. Please make sure that you are rendering the XML layout for the compiled SDK version (Must not be greater) . Means you will face this if you are compiling the code using Targeted SDK version 23 and your trying to render the XML in SDK version 24.

Muhamed Riyas M
  • 5,055
  • 3
  • 30
  • 31
0

There are several thing to remember when set the STUDIO_JDK on Mac OS:

  • by default Apple's Java 1.6 is used to start the Android Studio
  • when the STUDIO_JDK is set to Oracle's Java it will be used by the Android Studio to run

The difference between two is that Apple's Java IMO provides nicer and better fonts antialiasing in the IDE.

A reply here is referencing a bug in Android Studio regarding the fonts antialiasing. The ticket is already closed but still rendering is different for Apple Java and Oracle SDK (I have v1.8.0_102). And the former still has better perception than the last.

Community
  • 1
  • 1
Mykola
  • 435
  • 4
  • 17
0

try to use in project Java 1.8 - download last version of JDK and install it(if JSK is absent)

Then add to build.gradle these lines android { ... // Configure only for each module that uses Java 8 // language features (either in its source code or // through dependencies). compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } // For Kotlin projects kotlinOptions { jvmTarget = "1.8" } }

Alexander
  • 411
  • 3
  • 4
-1

machine: windows8 64bit in my case the jdk1.7 I had installed was 32bit hence I was using studio.exe (32bit) so even when I downloaded the new jdk1.8 (64bit) the studio instance I was using (32bit) couldn't detect it, but when I uninstalled the older jdk and tried to rerun studio.exe I was told to install a 32bit jdk. so I ran studio64.exe and it ran smoothly. ensure you have the correct path in your environment variables. cheers android N

-1

Make sure you have installed jdk for x64 and not x84 when starting Android Studio (x64)

enter image description here

user1564762
  • 745
  • 2
  • 11
  • 18