简体   繁体   中英

How to make Android studio embedded JDK use local documentation path

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM