I am launching a new Android Studio 3.0-beta7 and trying to use @nicopico's answer, but it did not work with a number of different errors, so here is an adaptation that does not rely on non-existent java.nio
utilities.
task javadoc(type: Javadoc) { failOnError false source = android.sourceSets.main.java.srcDirs // Also add the generated R class to avoid errors... // TODO: debug is hard-coded source += "$buildDir/generated/source/r/debug/" // ... but exclude the R classes from the docs excludes += "**/R.java" // TODO: "compile" is deprecated in Gradle 4.1, // but "implementation" and "api" are not resolvable :( classpath += configurations.compile afterEvaluate { // Wait after evaluation to add the android classpath // to avoid "buildToolsVersion is not specified" error classpath += files(android.getBootClasspath()) // Process AAR dependencies def aarDependencies = classpath.filter { it.name.endsWith('.aar') } classpath -= aarDependencies aarDependencies.each { aar -> System.out.println("Adding classpath for aar: " + aar.name) // Extract classes.jar from the AAR dependency, and add it to the javadoc classpath def outputPath = "$buildDir/tmp/exploded-aar/${aar.name.replace('.aar', '.jar')}" classpath += files(outputPath) // Use a task so the actual extraction only happens before the javadoc task is run dependsOn task(name: "extract ${aar.name}").doLast { extractEntry(aar, 'classes.jar', outputPath) } } } } // Utility method to extract only one entry in a zip file private def extractEntry(archive, entryPath, outputPath) { if (!archive.exists()) { throw new GradleException("archive $archive not found") } def zip = new java.util.zip.ZipFile(archive) zip.entries().each { if (it.name == entryPath) { def path = new File(outputPath) if (!path.exists()) { path.getParentFile().mkdirs() // Surely there a simpler is->os utility except // the one in java.nio.Files? Ah well... def buf = new byte[1024] def is = zip.getInputStream(it) def os = new FileOutputStream(path) def len while ((len = is.read(buf)) != -1) { os.write(buf, 0, len) } os.close() } } } zip.close() }
My concern is that we need all this code to create freaking javadoc for the library, but at least I got this working. However, I need to find a workaround for the .api configuration and configuration.implementation are not solvable.
source share