0

Recently I created gradle task to build JavaDoc. It was working flawlessly.

After a while I decided to clean the mess in my file structure and moved my classes in separate packages according to their purpose. I fixed some errors that came with it and now my app works like before, but after that my JavaDoc task stopped working (the project builds and works as intended).

I tested this build with previous file structure (all files in 1 package) and Javadoc compiled successfully.

I think it comes down to my poor knowledge of gradle, but I can't figure out how to get JavaDoc task working with my new file structure.

enter image description here

enter image description here

My build.gradle:

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    classpath += configurations.javadocDeps

    options.memberLevel = JavadocMemberLevel.PRIVATE

    afterEvaluate {
        classpath += files(android.getBootClasspath())

        def aarDependencies = classpath.filter { it.name.endsWith('.aar') }
        classpath -= aarDependencies
        aarDependencies.each { aar ->

            def outputPath = "$buildDir/tmp/aarJar/${aar.name.replace('.aar', '.jar')}"
            classpath += files(outputPath)

            dependsOn task(name: "extract ${aar.name}").doLast {
                extractEntry(aar, 'classes.jar', outputPath)
            }
        }
    }
}

private static def extractEntry(archive, entryPath, outputPath) {
    if (!archive.exists()) {
        throw new GradleException("archive $archive not found")
    }

    def zip = new ZipFile(archive)
    zip.entries().each {
        if (it.name == entryPath) {
            def path = Paths.get(outputPath)
            if (!Files.exists(path)) {
                Files.createDirectories(path.getParent())
                Files.copy(zip.getInputStream(it), path)
            }
        }
    }
    zip.close()
}
VeceluXa
  • 17
  • 1
  • 7
  • Hopefully the links at the top of your question will help you solve this. – Code-Apprentice Nov 28 '21 at 06:13
  • 1
    @Code-Apprentice, unfortunately no. The 4 links relate to the situation where the project does not compile successfully so the generated "R" class is not generated. – Seynorth Jan 13 '22 at 09:00
  • 1
    I am facing the same problem as @VeceluXa, when generating the javadoc on the project compiling well, the generation indicates that it cannot resolve symbol "R" imported in several classes. – Seynorth Jan 13 '22 at 09:01

0 Answers0