Background: Launching Android Studio 3.0-beta7 and trying to get the javadoc task to work in the Android library (the fact that this is not available as a finished task is really strange in the first place), and I was able to configure the answer to another question for my needs ending with this code ( https://stackoverflow.com/a/4646268/ ):
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() }
This code tries to find all the AAR: s dependency, goes through them and extracts classes.jar from them and puts them in a temporary folder, which is added to the class path during javadoc generation. It basically tries to reproduce what the really old android gradle plugin used to do with "exploded-aar".
However, the code depends on the use of compile
dependencies. Using api
or implementation
recommended with gradle 4.1 will not work, as they cannot be resolved from the gradle task.
Question: how can I get a list of dependencies using api
or implementation
directives, when, for example, configuration.api
displays an "unsolvable" error?
Bonus question: is there a new, better way to create javadocs for a library with Android Studio 3.0 that does not include 100 lines of workarounds?
source share