4

Pick the right JDK for Android Studio

 6 months ago
source link: https://kau.sh/blog/studio-jdk/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Pick the right JDK for Android Studio

Kaushik Gopal

If Android developers don’t setup the JDK correctly, you’ll be greeted with nasty errors like this:

error shown in Android Studio when incorrect jdk used
Check your module classpath error
Cannot access 'java.lang.constant.Constable' 
which is a supertype of 'java.lang.Class'. 
Check your module classpath for missing or conflicting dependencies

Your app might compile fine but the IDE will keep surfacing pesky errors. This is because Android developers have a variety of ways to setup the JDK for your development environment. Too many.

On episode #249 of Fragmented we discussed the numerous JDK options and what they’re used for. Google now has an excellent developer doc for this1.

If you don’t have time to catch up on all the valuable content above, here’s the takeaways:

1. Use the JDK that comes with Android Studio

JBR2 is battle tested with Android Studio and includes enhancements for running Android Studio well. To use it as your SDK, switch your Gradle JDK to JBR:

pick JBR
how to set jbr as your gradle jdk

Do a File > Invalidate Caches after this…

Famous Android Studio option - Invalidate Caches
mother of all fixes

2. Match yourJAVA_HOME with the Gradle JDK

The Gradle JDK from Step 1 is used to compile your app from Android Studio. If you use the command line to build your app on the other hand, the JDK from your $JAVA_HOME3 is used.

If both of these don’t match, you can have multiple gradle daemons running around. Make sure to match the two.

# ~/.zshenv
export JAVA_HOME=$HOME/Applications/Android\ Studio.app/Contents/jbr/Contents/Home

If you’re not sure where the jbr-jdk is located:

JBR path

This is the way.


  1. no seriously, it’s really good. ↩︎

  2. JetBrains Runtime ↩︎

  3. …if you haven’t customized your environment too much. It’s a little more involved↩︎


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK