Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right way to exclude R.java from javadoc using gradle

I'm generating javadoc for my Android project with this gradle task:

android.applicationVariants.all { variant ->
    task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
        description "Generates Javadoc for $variant.name."
        source = variant.javaCompile.source
        classpath = files(variant.javaCompile.classpath.files, project.android.getBootClasspath())
        exclude '**/BuildConfig.java'
        exclude '**/R.java'
        options.links("http://docs.oracle.com/javase/7/docs/api/");
        options.linksOffline("http://d.android.com/reference","${android.sdkDirectory}/docs/reference");
        options {
            failOnError false
        }
        destinationDir = file("${project.projectDir}/javadoc")
    }
}

It excludes R.java, so i don't get R.html in output dir. However, i'm getting very annoying errors cannot find symbol class R in the process of generating doc for my usual java classes, in the line import com.mypackagename.R. I use common android things like R.string.string_res, so i can't remove this import. Is there a proper way to include symbol R to index, but not include it to a javadoc, or, at least, simply to supress this error?

like image 240
sandwwraith Avatar asked May 19 '16 02:05

sandwwraith


1 Answers

You can try to add next two lines to your code:

classpath += files("build/generated/source/r/${variant.flavorName}/release")
classpath += files("build/generated/source/buildConfig/${variant.flavorName}/release")

But in this case your task should depend on one of the tasks which generates R classes.

like image 87
drjunja86 Avatar answered Sep 19 '22 19:09

drjunja86