2

I use Android studio 2.2, and use the embedded JDK as my project's JDK, this is the recommended way as the settings show.

My project has a java module run on the host. When I working on this java module, the popup menu show Fetching documentation... and take a little time to show the documentation every time I want to look up documentation of some Java APIs.

I have another version JDK installed on my host, /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home

so I try to change several lines of the file ~/Library/Preferences/AndroidStudio2.2/options/jdk.table.xml from

<javadocPath>
    <root type="composite">
        <root type="simple" url="http://docs.oracle.com/javase/8/docs/api" />
    </root>
</javadocPath>

to

<javadocPath>
      <root type="composite">
          <root type="simple" url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/src.zip!/" />
          <root type="simple" url="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/javafx-src.zip!/" />
      </root>                          
</javadocPath>

But after I restart Android studio, my changes didn't take effect. When I look up the documentation, it's till very slow, and the content of jdk.table.xml has recover back, javadocPath url path still point to http://docs.oracle.com/javase/8/docs/api.

How can I use local JDK documentation in Android studio with embedded JDK?

3
  • 1
    Download the sources inside Android SDK Manager for your platform. That way Android Studio shows the local docs. Commented Jan 25, 2017 at 8:19
  • Android SDK Manager only provide Documentation for Android SDK, what I need is java sdk documentation. Commented Jan 25, 2017 at 8:24
  • You're wrong there, it also provides documentation for the JDK. Commented Jan 25, 2017 at 8:27

1 Answer 1

1

Link (or copy) src.jar into jre dir

I had a similar problem here. Your attempts inspired me to try something else: linking the src.zip file from the local JDK install into Android Studio's jre directory. Let's say your Android Studio is at $ANDROID_STUDIO_HOME_DIR:

# assuming you're on something *nix-y
$ ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/src.zip $ANDROID_STUDIO_HOME_DIR/jre/src.zip

After a restart that seems to work[*]. Appropriate-seeming values were automatically added to the jdk.table.xml file, and everything survived further restarts. Of course, copying the file into place would work the same, but I think I'll find the soft-link a useful reminder of this hack...

[*]: I guess if you were using JavaFX you'd need to do the same for javafx-src.zip, too.


Hiccup on Android Studio update

Later: This change didn't survive the next update to Android Studio. The update process (2.2 to 2.3) threw up a dialog about a patch conflict involving the src.jar file that I'd added. After dismissing that dialog the update ran to completion. Studio then seemed to be working fine, except that once again the quick documentation for my java module was missing. I re-added the link to src.jar to get it working again.


Using API documentation instead

Just for completeness, I also discovered a way to use a copy of the API documentation instead of a local JDK's src.zip. API documentation will be picked up if it's linked/copied to $ANDROID_STUDIO_HOME_DIR/jre/docs/api.

So, to use the Documentation for Android SDK mentioned above:

$ mkdir $ANDROID_STUDIO_HOME_DIR/jre/docs
$ ln -s ~/android-sdks/docs/reference $ANDROID_STUDIO_HOME_DIR/jre/docs/api

or, if you've a copy of Oracle's jdk-xxx-docs-all.zip unzipped at $JDK_DOCS:

$ mkdir $ANDROID_STUDIO_HOME_DIR/jre/docs
$ ln -s $JDK_DOCS/api $ANDROID_STUDIO_HOME_DIR/jre/docs/api
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.