Developing for the Android L Developer Preview on OSX

To get started I followed the instructions on the L Developer Preview site. That lead me through updating all of the required tools and packages and setting up the emulator. I created a new project in Android Studio and was able to select Android L Preview as the target but when it tried to build I got the following message:

Error:compileSdkVersion android-L requires compiling with JDK 7

Alright, so I'll just install JDK 7, right? I downloaded the jdk-7u60-macosx-x64.dmg installer from Oracle's site and tried to install it. That gave me this message:

Java from Oracle requires Mac OS X 10.7.3 or later.

Your system has Mac OS X Version 10.10. This product can be installed on Version 10.7.3 or later.
Visit java.com/help for more information.

It turns out that the test in the installer that checks for a supported OS fails in Yosemite. So I managed to find this blog post that ran me though these steps to fix that issue.

  1. Download JDK 7
  2. Open the DMG
  3. Run pkgutil --expand "/Volumes/JDK 7 Update 60/JDK 7 Update 60.pkg" "/tmp/JDK 7 Update 60.unpkg"
  4. Go to /tmp/JDK\ 7\ Update\ 60.unpkg
  5. Open the Distribution file in your favorite editor
  6. Change the function pm_install_check() to always return true
  7. Run pkgutil --flatten "/tmp/JDK 7 Update 60.unpkg" "/tmp/JDK 7 Update 60.pkg"
  8. Run open "/tmp/JDK 7 Update 60.pkg"

Ok, so now I double checked the Java version:

$ java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

Perfect! I launched Android Studio again and saw the same error. That's ok, I probably just needed to set the path to the new JDK. So this time I clicked the link to the settings page and set the path to the JDK to /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home. This cleared up the error and finally let me push the test app to my Nexus 5!