Android N requires the IDE to be running with Java 1.8 or later?

60,305

Solution 1

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.

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

  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.

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.

First row of icons in the rpeview window

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.

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.

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.

Share:
60,305

Related videos on Youtube

mihirjoshi
Author by

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, 2020

Comments

  • mihirjoshi
    mihirjoshi about 4 years

    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

    • CommonsWare
      CommonsWare over 8 years
      There 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
      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
      Phyrum Tea over 8 years
      I had to change to buildToolsVersion '24.0.0 rc1', the documentation was missing the quotes.
    • mihirjoshi
      mihirjoshi over 8 years
      @PhyrumTea Didn't make the error go away.
    • Phyrum Tea
      Phyrum Tea over 8 years
      The error message suggest, that android studio was started with other (wrong) JDK. What is in the about box? Help->About
    • mihirjoshi
      mihirjoshi over 8 years
      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 and google is working on it.
    • Suragch
      Suragch almost 8 years
  • mihirjoshi
    mihirjoshi over 8 years
    But I want to preview in N not in API 23.
  • santhyago
    santhyago over 8 years
    This 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
    Kotik_o about 8 years
    It works! Thanks for this solution. The question is: Why Google wants that his developers wasted his time on this issues?
  • Totalys
    Totalys about 8 years
    Thanks 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#java‌​8 (This is the link displayed at android studio).
  • Micro
    Micro about 8 years
    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: <key>JVMVersion</key> <string>1.8</string> So annoying Android Studio!
  • The_Martian
    The_Martian about 8 years
    I did what you said but when I do help->about it still points to my old jdk. Why is that?
  • Zapnologica
    Zapnologica about 8 years
    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.
  • terencey
    terencey about 8 years
    @The_Martian you need to restart your computer.
  • lopez.mikhael
    lopez.mikhael about 8 years
    On Mac Os I remove my old jdk version. After that, Android Studio pick the last version
  • jmnwong
    jmnwong about 8 years
    Android Studio 2.2 uses <string>1.8*,1.8+</string>.
  • Mike
    Mike about 8 years
    Mine still says "partially installed" after reinstalling.
  • Micro
    Micro almost 8 years
    is that safe to do
  • youngwind
    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
    mythicalcoder almost 8 years
    Mine too "partially installed" after reinstalling. @Andrew did you find any solution afterwards ?
  • mythicalcoder
    mythicalcoder almost 8 years
    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" ?
  • Mike
    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
    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
    mythicalcoder almost 8 years
    You 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
    Nishant Srivastava almost 8 years
    So 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
    Showpath almost 8 years
    This 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
    Saima almost 8 years
    I experienced the same issue on my mac. lowering the API level from 24 to 23 worked for me.
  • Terix
    Terix almost 8 years
    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
  • Pavneet_Singh
    Pavneet_Singh almost 8 years
    not an answer , please follow the answer marked as right
  • Dustin Butler
    Dustin Butler almost 8 years
    This worked for me on Mac! Thank you! I am on OS X El Capitan 10.11
  • Daniele
    Daniele almost 8 years
    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
  • wumbo
    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
    0xC0DED00D almost 8 years
    Do not do this, it'll mess with Android Studio updates. Just change STUDIO_JDK environment path.
  • enadun
    enadun almost 8 years
    This is not an answer. This is just ignoring the problem environment.
  • Milon
    Milon almost 8 years
    how to open this file? I am using Mac but could not find that location.
  • arango_86
    arango_86 over 7 years
    Nicely done. Yes, It solved my problem. Thank you. :)
  • zgc7009
    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.