prevent Javadoc from failing gradle build - android

I’m trying to upload my Library project to jCenter.
when I run gradlew install I’m getting the error:
Execution failed for task ':myLibraryProject:javadoc'
I added the code below to my library project:
task androidJavadocs(type: Javadoc) {
failOnError false // add this line
source = android.sourceSets.main.java.getSrcDirs()
}
but still I get
"Javadoc generation failed. Generated Javadoc options file..."
I've also tried the accepted answer from here: Generate JavaDocs with Android Gradle plugin
Can I disable the generation of Javadocs, or maybe try to continue with the build although the failure?

Add these lines to your module build.gradle
tasks.withType(Javadoc) {
failOnError false
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
}
Or you can add these:
android.libraryVariants.findAll { variant -> variant.name == 'Release' } each { variant ->
task("generate${variant.name}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar = "${android.plugin.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
}
task("bundle${variant.name}Javadoc", type: Zip) {
description "Bundles Javadoc into zip for $variant.name."
classifier = "javadoc"
from tasks["generate${variant.name}Javadoc"]
}

I don't recommend disabling JavaDoc generation. Instead, try just running
./gradlew javadoc
This should give you detailed log output about the warnings and errors that are occurring. Fixing these errors should prevent JavaDoc from causing the failure.

In our case, the problem was that we had to remove .gitignore files. They were listed in the file javadoc.options. After that, the task finished successfully.

Run your app without --deviceID. Just run npx react-native run-android . It works for me.

Related

Could not get unknown property 'manifestOutputDirectory'

I'm trying to "make project" with Android Studio, and I'm getting this error:
Execution failed for task ':myApp:processGoogleDebugManifest'.
Could not get unknown property 'manifestOutputDirectory' for task ':myApp:processGoogleDebugManifest' of type com.android.build.gradle.tasks.ProcessMultiApkApplicationManifest.
Any help please?
EDIT: This error occurred after I updated to gradle v6.5 and plugin v4.1.0. If I revert to gradle v6.1.1 and plugin v4.0.0 the error disappears.
I encountered this same issue today, in my case it was caused by an outdated version of Huawei's AG Connect plugin. I was using com.huawei.agconnect:agcp:1.2.1.301, but when I updated it to com.huawei.agconnect:agcp:1.4.1.300 the issue was fixed.
See Latest Huawei's AG Connect plugin here: https://developer.huawei.com/latest/plugin/agconnect ...Just scroll, you'll find it there haha!
But if Huawei's plugin is not the problem you are having, you can debug the issue by running gradle with --stacktrace option to see where the issue originates from. In Android Studio you can add command line options for gradle in Settings/Build, Execution, Deployment/Compiler/Command-line options.
This solved my same problem:
In the project level build.gradle, replace this:
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
with this:
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
Reference: https://github.com/Tencent/tinker/issues/1471#issuecomment-710777366
If you're using bugsnag, replace the following line
classpath 'com.bugsnag:bugsnag-android-gradle-plugin:4.+'
with:
classpath 'com.bugsnag:bugsnag-android-gradle-plugin:5.+'
For further detail, see this issue: Fails with AGP 4.1.0-alpha04 and this comment.
I write it here because this solution saved my day :
We can fix this by simply replacing references to
manifestOutputDirectory
by
multiApkManifestOutputDirectory
enter code here
in your gradle tasks
For example :
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
output.processManifest.doLast { task ->
def outputDir = multiApkManifestOutputDirectory.asFile.get()
String manifestMergerpath = "$outputDir/AndroidManifest.xml"
writeManifest(manifestMergerpath, placeholders)
}
}
}
android.applicationVariants.all {
outputs.all {
processManifestProvider.configure {
val multiApkManifestOutputDirectory = (this as ProcessMultiApkApplicationManifest)
.multiApkManifestOutputDirectory // 👈
doLast {
multiApkManifestOutputDirectory.get()
.asFile
.walkTopDown()
.forEach {
}
}
}
}
}

Android gradle Upload NDK symbols on every build

I want to upload NDK symbols on every build i do,
Under my Android inside gradle i use to have:
applicationVariants.all { variant ->
def variantName = variant.name.capitalize()
println("symbols will be added on varinat ${variantName}")
def task = project.task("ndkBuild${variantName}")
task.finalizedBy project.("uploadCrashlyticsSymbolFile${variantName}")
}
this does not compile anymore since i moved to FireBase :
Could not get unknown property 'uploadCrashlyticsSymbolFile
I don't see this task running.
I basiclly need this task to run on every build:
./gradlew app:assembleBUILD_VARIANT\
app:uploadCrashlyticsSymbolFileBUILD_VARIANT
Add this at the bottom of app's build.gradle outside android { ... } block.
afterEvaluate {
android.applicationVariants.all { variant ->
def variantName = variant.name.capitalize()
println("symbols will be added on variant ${variantName}")
def task = tasks.findByName("assemble${variantName}")
def uploader = "uploadCrashlyticsSymbolFile${variantName}"
// This triggers after task completion
task?.finalizedBy(uploader)
// This ensures ordering
task?.mustRunAfter(uploader)
}
}
You can try without afterEvaluate block. It should still work.
Likely you'd need to use Firebase App Distribution, which permits automatic upload of release build artifacts - and if you have the artifact with the matching debug symbols, they could actually be used - without the matching assembly, the symbols are somewhat irrelevant.
Number 1 is obviously a wrongful assumption, because the documentation clearly states:
./gradlew app:assembleBUILD_VARIANT app:uploadCrashlyticsSymbolFileBUILD_VARIANT
And this is already answered here.
In order to always upload, one can create a task dependency:
assembleRelease.finalizedBy uploadCrashlyticsSymbolFileRelease
This may require setting unstrippedNativeLibsDir and strippedNativeLibsDir.

Gradle: How to run custom task after an Android Library is built?

I have an Android Library, it's generating a debug.aar and a release.aar, I need to copy the release.aar to another folder as a reference to other part of the project.
What I've done now is in this Android Library build.gradle I defined a task:
task copyAARToCommonLibs(type: Copy) {
from('../build/outputs/aar') {
include '*-release.arr'
}
into '../SomeSampleApps/libs'
}
I'm trying to run this task after the arr is generated, which I assume is assembleRelease stage, so I tried do this in this build.gradle
assembleRelease.doLast{
copyAARToCommonLibs
}
I build the overall project using
gradle build
But this task is running at the very beginning of the whole process.
I also tried this:
applicationVariants.all { variant ->
variant.assemble.doLast {
copyAARToCommonLibs
}
}
inside android{} property(I guess that's what it's called?)
Running gradle build, got this error: Could not find property 'applicationVariants'
I then came across this snippet:
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyAARToCommonLibs }
But it seems this makes the task to run after compiling, I don't know exactly how to modify this to run after assemble.
Could someone please correct me where I did wrong and how can I get this copy task work after the .arr file is generated?
It seems that finalizedBy might be helpful.
assembleRelease.finalizedBy(copyAARToCommonLibs)
Mind the fact that in the following way you won't define a dependency:
assembleRelease.doLast {
copyAARToCommonLibs
}
actually.. it does exactly nothing. You need to execute the task:
assembleRelease.doLast {
copyAARToCommonLibs.execute()
}
but running task in the following way is discouraged and very bad practice.
You can also try:
assembleRelease.doLast {
copy {
from('../build/outputs/aar') {
include '*-release.aar'
}
into '../AscendonSDKSamples/libs'
}
}
I went with finalizedBy() but had to include it within an afterEvaluate...
afterEvaluate {
if (gradle.startParameter.taskNames.contains(":app:assembleFatReleaseInternal")) {
play.enabled = true
play.commit = true
play.track = "internal"
play.releaseStatus = "completed"
play.releaseName = versionName
generateFatReleaseInternalBuildConfig.dependsOn set_build_date
assembleFatReleaseInternal.finalizedBy(uploadCrashlyticsSymbolFileFatReleaseInternal)
uploadCrashlyticsSymbolFileFatReleaseInternal.finalizedBy(publishFatReleaseInternal)
}
}
This worked well for automating the upload of native symbols to Fabric / Crashlytics and other things such as automated play store publishing.
Because android studio add task by dynamic,so assembleRelease will not be recognized.
Just add hook after task added event happens.
tasks.whenTaskAdded {
theTask ->
if (theTask.name.contains('externalNativeBuild')) {
theTask.doLast{
println "[*] begin to copy file."
}
}
// println theTask.name
}

Gradle print path of used jars in gradle init script

I need to print the path of the jar files used by gradle.
Currently if I include the following lines in my top folder gradle project I am able to get the correct information:
allprojects {
task printDependencies << {task -> println "Subproject -> $task.project.name" }
}
subprojects {
printDependencies {
afterEvaluate { Project project ->
if (configurations.find { it.name == 'compile' }) {
doLast {
println "$project.configurations.compile.asPath\n"
}}}}}
Now I wanted to include this behavior into a init script as to avoid copying this code to all my build.gradle files.
The problem is I cannot get it to work at ${HOME}/.gradle/somename.gradle. The first error that pops up is:
Could not find method subprojects() for arguments
Is there any way to put this behaviour in a gradle init file?
Gradle build scripts delegate to an instance of the Project class (see chapter 13 Gradle User guide), so that is where the subprojects method comes from.
However init scripts delegate to an instance of Gradle (see 60.3 Gradle User guide), which does not have a subprojects method.
It does have a rootProject method,so you probaby want something like
projectsEvaluated {
rootProject.subprojects {
...
}
}

Gradle, Javadoc and Android documentation

I'm now using Gradle for all my projects, and even for javadoc generation.
android.libraryVariants.all { variant ->
task("generate${variant.name}Javadoc", type: Javadoc) {
title = "$name $version API"
source = variant.javaCompile.source
ext.androidJar = "${android.plugin.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
ext.googlePlayServicesJar = "${android.plugin.sdkDirectory}/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar"
classpath = files(variant.javaCompile.classpath.files, ext.androidJar, ext.googlePlayServicesJar)
options.links("http://docs.oracle.com/javase/7/docs/api/");
options.links("http://d.android.com/reference/");
//options.linksOffline("http://d.android.com/reference", "${android.plugin.sdkDirectory}/docs/reference");
exclude '**/BuildConfig.java'
exclude '**/R.java'
}
}
With that code I got everything working, except one thing: regular Android API objects like Activity, Bitmap etc.
Java's links are working fine.
The final generated documentation does not link to http://d.android.com/reference.
I tried both options.links() and options.linksOffline() without success.
EDIT
Thanks to #ejb, the problem was that you cannot provide multiple options.links() at the same time.
So I used both options.links() for Java's documentation and options.linksOffline() for Android's documentation:
options {
links("http://docs.oracle.com/javase/7/docs/api/");
linksOffline("http://d.android.com/reference", "${android.plugin.sdkDirectory}/docs/reference");
//stylesheetFile = new File(projectDir, "stylesheet.css");
}
I was able to successfully link to http://d.android.com/reference using the following snippet which is functionally exactly what you have (as far as I can tell).
android.libraryVariants.all { variant ->
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
// title = ''
// description = ''
source = variant.javaCompile.source
classpath = files(variant.javaCompile.classpath.files, project.android.getBootClasspath())
options {
links "http://docs.oracle.com/javase/7/docs/api/"
linksOffline "http://d.android.com/reference","${android.sdkDirectory}/docs/reference"
}
exclude '**/BuildConfig.java'
exclude '**/R.java'
}
}
So there is something else amiss here.
You have to build the javadoc offline, as it doesn't seem the package-list is available on the path of the web service. Maybe double check that you actually have the docs loaded locally, and make sure there is a package-list in the /[android-sdk]/docs/reference directory.
If you still can't figure it out, perhaps you could post output.
Another thing you might check is the ./build/tmp/[taskname]/javadoc.options, the head of said file should show the appropriate options carefully set. Things to check for would include the proper inclusion of the android.jar in the -classpath and the presence of linksOffline with expected arguments: -linksoffline extDocURL packageListLoc
javadoc.options should have both options with only the respective arguments:
-linksoffline 'http://d.android.come/reference' '[sdkDir]/docs/reference'
-links 'http://docs.oracle.com/javase/7/docs/api/'
EDIT: android.getBootClasspath() is nicer, thanks to P-chan.
For Android Gradle plugin 1.1.2+ (com.android.tools.build:gradle:1.1.+)
libraryVariants - does not work anymore
use:
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
destinationDir = file("../javadoc/")
failOnError false
}
destinationDir = file("../javadoc/") - locate javadocs at root of project directory (in this way jenkins javadoc plugin could find it and show in special Document panel)
failOnError false - for suppress warnings that can cause fail build on jenkins
Alternative for Gradle JavaDocs
Doxygen - cross reference documentation tool.
could be run from UI or terminal: http://www.doxygen.nl/manual/doxygen_usage.html
Generating javadoc available throw java tool: 'javadoc'
run from command line:
javadoc -d docs -sourcepath app/src/main/java -subpackages com
docs - destination folder

Categories

Resources