1

I am trying to generate javadoc for android application using a command or a gradle task. I tried this command:

javadoc -protected -splitindex  -bootclasspath /Users/[username]/Library/Android/sdk/platforms/android-29/android.jar -Xdoclint:none -sourcepath app/src/main/java -subpackages .

And the result was:

error: package androidx.appcompat.app does not exist import androidx.appcompat.app.AppCompatActivity;

Also I've tried tasks like this :

task createJavadocs (type: Javadoc) {
    source = project.android.sourceSets.main.java.srcDirs
    options.linkSource true
    classpath += project.files(project.android.getBootClasspath().join(File.pathSeparator))
    failOnError false  
}

Which gives the same output.

Waqar UlHaq
  • 6,144
  • 2
  • 34
  • 42
  • You can get your answer here: https://stackoverflow.com/questions/29162820/how-to-create-javadoc-using-android-studio-without-r-and-buildconfig – Muhammad Zahab Feb 22 '20 at 20:23
  • @MuhammadZahabAhmedKhan that is not what I asked for. I want to do it without using android studio. – Peter Ragheb Feb 22 '20 at 20:25
  • Your error seems like you don't added 'androidx.appcompat:appcompat:1.0.0' support library. You need to add support library then your problem will get resolved. – Muhammad Zahab Feb 22 '20 at 20:28
  • @MuhammadZahabAhmedKhan It's already added in the dependencies. And the project compiles just fine. This error is Javadoc related. – Peter Ragheb Feb 22 '20 at 20:29

1 Answers1

0

I had the same problem until I came across this answer: https://stackoverflow.com/a/29164335/10365305

This is how I adapted the build.gradle file for my needs:

android.applicationVariants.all { variant ->
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
    description "Generates Javadoc for $variant.name."

    //(project.android.sourceSets.main.java.srcDirs also works if you don't care about variants)
    source = variant.javaCompile.source 
    destinationDir = file("$rootDir/javadoc/")
    failOnError false

    doFirst {
        ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
        classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)

        // I used a custom doclet
        options.docletpath = configurations.umlDoclet.files as List
        options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"

        options.addStringOption "-show-members", "package"
        // more doclet options here...
       
        options.links "https://developer.android.com/reference/"
    }
}}

This will generate multiple gradle tasks for each of your build variants. To see a list of the tasks that have been generated this way, use gradlew tasks --all. For me, this generated the task app:generateReleaseJavadoc.

Running this task should not (hopefully) lead to the error you mentioned.

(I know this is a rather old question but maybe it will help someone.)

jonasstr
  • 57
  • 3
  • 9