I'm now using Gradle for all my projects, and even for javadoc generation.
android.libraryVariants.all { variant -> task("generate${variant.name}Javadoc", type: Javadoc) { title = "$name $version API" source = variant.javaCompile.source ext.androidJar = "${android.plugin.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar" ext.googlePlayServicesJar = "${android.plugin.sdkDirectory}/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar" classpath = files(variant.javaCompile.classpath.files, ext.androidJar, ext.googlePlayServicesJar) options.links("http://docs.oracle.com/javase/7/docs/api/"); options.links("http://d.android.com/reference/"); //options.linksOffline("http://d.android.com/reference", "${android.plugin.sdkDirectory}/docs/reference"); exclude '**/BuildConfig.java' exclude '**/R.java' } }
With that code I got everything working, except one thing: regular Android API objects like Activity, Bitmap etc. Java's links are working fine.
The final generated documentation does not link to http://d.android.com/reference. I tried both options.links() and options.linksOffline()
without success.
EDIT
Thanks to @ejb, the problem was that you cannot provide multiple options.links()
at the same time. So I used both options.links()
for Java's documentation and options.linksOffline()
for Android's documentation:
options { links("http://docs.oracle.com/javase/7/docs/api/"); linksOffline("http://d.android.com/reference", "${android.plugin.sdkDirectory}/docs/reference"); //stylesheetFile = new File(projectDir, "stylesheet.css"); }
Generating JavadocsApplying the Java plugin to a Gradle build script automatically provides a task for generating Javadocs out-of-the-box. That task is called javadoc , takes the compiled source code from the main source set as input and builds a set of HTML pages as output.
The javadoc command parses the declarations and documentation comments in a set of Java source files and produces a corresponding set of HTML pages that describe (by default) the public and protected classes, nested classes (but not anonymous inner classes), interfaces, constructors, methods, and fields.
The BEA WebLogic Java Adapter for Mainframe (JAM) product comes with HTML pages that document the JAM Java classes. These also are referred to as "javadoc" files. They are located in the jamdoc. jar file, found in the JAM installation directory.
I was able to successfully link to http://d.android.com/reference using the following snippet which is functionally exactly what you have (as far as I can tell).
android.libraryVariants.all { variant -> task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) { // title = '' // description = '' source = variant.javaCompile.source classpath = files(variant.javaCompile.classpath.files, project.android.getBootClasspath()) options { links "http://docs.oracle.com/javase/7/docs/api/" linksOffline "http://d.android.com/reference","${android.sdkDirectory}/docs/reference" } exclude '**/BuildConfig.java' exclude '**/R.java' } }
So there is something else amiss here.
You have to build the javadoc offline, as it doesn't seem the package-list
is available on the path of the web service. Maybe double check that you actually have the docs loaded locally, and make sure there is a package-list
in the /[android-sdk]/docs/reference
directory.
If you still can't figure it out, perhaps you could post output.
Another thing you might check is the ./build/tmp/[taskname]/javadoc.options
, the head
of said file should show the appropriate options carefully set. Things to check for would include the proper inclusion of the android.jar in the -classpath and the presence of linksOffline with expected arguments: -linksoffline extDocURL packageListLoc
javadoc.options
should have both options with only the respective arguments:
-linksoffline 'http://d.android.come/reference' '[sdkDir]/docs/reference' -links 'http://docs.oracle.com/javase/7/docs/api/'
EDIT: android.getBootClasspath()
is nicer, thanks to P-chan.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With