I'm trying to build an aar to publish on jcenter.
The assembleRelease task works ok, the javadoc task also works fine, but the javadocJar task outputs this error:
/Users/martinmoreno/Projects/android-dev-utils/dev-utils/src/main/java/com/tinchoapps/devutils/BitmapUtils.java:11: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
Here is the (simplified) gradle file:
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
...
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
}
...
}
...
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-annotations:20.0.0'
compile 'com.android.support:support-v4:22.0.0'
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
destinationDir = file("../javadoc/")
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
It seems related to the dependencies because it's giving some "class not found" exceptions too on classes inside the imports, but can't figure out what's wrong.
Any thoughts?
This fixed various similar errors for me:
Add the following to build.gradle:
configurations {
javadocDeps
}
dependencies {
compile 'com.android.support:support-annotations:22.2.0'
javadocDeps 'com.android.support:support-annotations:22.2.0'
androidTestCompile 'junit:junit:4.+'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:+'
}
In the JavaDoc Task add this line:
classpath += configurations.javadocDeps
Just add this line in your javadoc task (notice the last part: + configurations.compile
):
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + configurations.compile
The last part of the line makes sure the javadoc use the compile dependencies to resolve the classes it's using for javadoc. At this point, it shouldn't fail anymore.
Since the introduction of the api
and implementation
dependency configuration in Android Gradle 3.0.0, compile
is deprecated. To include an implementation
dependency in the javadoc classpath, I updated Loius CADs answer:
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
configurations.implementation.setCanBeResolved(true)
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + configurations.implementation
}
I don't expect this to be the cleanest solution possible. There probably is a reason why configuration.implementation
is not resolvable by default.
I've faced this while running ./gradlew install
. It was occurring when JavaDocs were being compiled (as far as I can understand).
I just added failOnError false
to task javadoc
.
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
failOnError false
}
What I understand is that we avoided failure on warnings that annotation library couldn't be found.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With