35

Thanks to this thread, I was able to get Javadoc links to work for my Android project within Eclipse on Windows. Specifically, "{@link android.widget.Toast}" is currently converted into a link to "http://d.android.com/reference/android/widget/Toast.html?is-external=true". I achieved this with the Javadoc option:

-linkoffline http://d.android.com/reference "file:/C:/Android/android-sdk-windows/docs/reference"

However, I get errors such as the following based on lines of my Java code (not the Javadoc comments):

C:\Users\Ellen\workspace\TestableToast\src\edu\mills\cs180\HelloAndroid.java:5: 
package android.view does not exist
import android.view.View;
                   ^ 
C:\Users\Ellen\workspace\TestableToast\src\edu\mills\cs180\HelloAndroid.java:6: 
package android.view.View does not exist 
import android.view.View.OnClickListener;
                        ^ 
C:\Users\Ellen\workspace\TestableToast\src\edu\mills\cs180\HelloAndroid.java:8: 
package android.widget does not exist
import android.widget.Toast;
                      ^ 
C:\Users\Ellen\workspace\TestableToast\src\edu\mills\cs180\HelloAndroid.java:10: 
cannot find symbol symbol: class Activity 
public class HelloAndroid extends Activity implements OnClickListener {
                                  ^

How can I fix these references?

Community
  • 1
  • 1
Ellen Spertus
  • 6,576
  • 9
  • 50
  • 101

8 Answers8

83

This Works in Eclipse for me:

  1. Project --> generate Javadoc
  2. Go to "Configure Javadoc arguments."
  3. in VM options add "-bootclasspath /path/to/sdk/platforms/android-##/android.jar"
David
  • 15,894
  • 22
  • 55
  • 66
Marcel D-B
  • 945
  • 7
  • 4
  • Same here. Thank you! :) – luthier Aug 29 '13 at 11:07
  • Its works without quotes for me. quotes generate unrecognized tag error. – Artur Szymański Aug 26 '14 at 12:43
  • 3
    This also works for Android Studio by the way. I just flawlessly generated a JavaDoc for my Android library project using **-bootclasspath /Users/username/Library/Android/sdk/platforms/android-22/android.jar** – bmeulmeester May 20 '15 at 14:22
  • This solution works for one developer, but not for a whole team. Isn't there a solution without a hardcoded local path? Something I could add to the gradle build task to publicize the classpath dynamically? – rickul Apr 29 '16 at 12:15
40

Adding -classpath parameter in the last screen of "Generate Javadoc..." wizard did not work for me: I got an error message saying that -classpath parameter can only be specified once.

Not really a solution, but a workaround:

  • In the "Generate Javadoc..." wizard, check the option "Save the settings of this Javadoc export as an Ant script". This generates javadoc.xml file in project directory
  • Edit javadoc.xml file and edit classpath attribute. Specifically, add "/path/to/sdk/platforms/android-##/android.jar" there and any other jars that you get warning messages about
  • Generate the javadoc with: ant -buildfile javadoc.xml. For convenience, I put this line in a javadoc.sh shell script.
Pēteris Caune
  • 43,578
  • 6
  • 59
  • 81
  • Thank you! I was finally able to generate my Javadoc. It might be worth adding that you can execute the buildfile from the Eclipse Ant View (adding the builfile and then run it). I had to do it that way as javadoc refused the -buildfile parameter. – Eric Tobias Jul 25 '13 at 10:39
  • 1
    I got the same error -- however, if you change the `-classpath` to `-bootclasspath` then it works fine. – Sandy D. Apr 13 '15 at 02:58
7

Project > generate Javadoc. Then, go to "Configure Javadoc arguments" and in VM options add "-bootclasspath /path/to/sdk/platforms/android-##/android.jar".

Worked for me :)

Antoine
  • 800
  • 3
  • 14
  • 29
Pushpan
  • 277
  • 3
  • 3
7

You need to put the android classes in your javadoc classpath, too. For this, add the android jar file to the -classpath argument of javadoc (as you would do for your compiler).

I have no idea whether and where Eclipse gives you some configuration option for this, though.

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
  • 4
    Thank you! That did it. The last screen in the "Generate Javadoc..." wizard allows the specification of command-line options, so I added '-classpath "C:/Android/android-sdk-windows/platforms/android-4/android.jar"'. – Ellen Spertus Mar 05 '11 at 00:22
  • I receive a "javadoc: error - The -classpath option may be specified no more than once., error now." – basickarl Nov 14 '13 at 08:42
  • 1
    @KarlMorrison if your command line already has a `-classpath ...` option, you should not add another one, but add the jar file to the existing one (separated by `;` on windows and `:` on unix systems). – Paŭlo Ebermann Nov 15 '13 at 18:27
4

Thanks to answer provided by @PaŭloEbermann and @MarcelD-B, I was able to understand the root cause of the issue. However, since I am using Android Studio, I was bit confused as to where to add the argument. After some time, I was able to figure it out finally and I am putting it as an answer here for any other person who finds the similar issue.

For Android Studio, open Tools > Generate JavaDocs and add the following argument in Other command line arguments:-

-bootclasspath /path/to/sdk/platforms/android-##/android.jar

Note:- There's no need of adding any commas in the argument. However, if your SDK Path contains spaces then enclose the path in double quotes ("). eg- My SDK Path contains spaces so I used the argument-

-bootclasspath "F:\Android SDK\platforms\android-21\android.jar"

JavaDoc generation screen on Android Studio

Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
3

the answers above are quite good! include the classpath in your javadoc.xml and run is via ant-command or eclipse -> Run As -> Ant Build

BUT be sure that there are no whitespaces in the paths! I had this problems with C:/Program Files/... and it didn't work till i changed it to C:/Progra~1/...

also putting the path in quotes didn't work for me.

zonky
  • 1,058
  • 9
  • 11
2

Windows Eclipse solution

Adding the android.jar to -classpath is indeed the correct approach. No ANT is necessary, though also viable. In case you want to be using Eclipse GUI (File->Export->Java->Javadoc) for generating Javadoc, there's no option to edit classpath in the dialog. You need to have the classpath set correctly beforehand. Two ways to achieve that:

  1. Edit manually the <path_to_your_project>/.classpath and add the following line:

    <classpathentry kind="lib" path="<path_to_your_android_skd>/platforms/android-<version>/android.jar"/>
    
  2. Right click on your project->Properties->Java Build Path->Libraries->Add External JARs->navigate to <path_to_your_android_skd>/platforms/android-<version>/android.jar

I found the Eclipse GUI approach better than using ANT hinted in some of the answers here because you get clickable references to your source code on any Javadoc warning/error in Console. When using ANT all you get in Console is printed output of the javadoc.exe command.

bocekm
  • 113
  • 7
1

This workaround in eclipse worked for me:

  1. Go to Project=>Properties and select "Java Build Path"
  2. Select "Order and Export" tab
  3. Move "android 2.x.x" and "Android Dependencies" to the top of the list
Suman
  • 11
  • 1