Is there a way to leverage the new functions withSourcesJar()
and withJavadocJar()
for Android library projects? Currently when I try to use it I get:
> SourceSet with name 'main' not found.
Class ProcessResourcesCopies resources from their source to their target directory, potentially processing them. Makes sure no stale resources remain in the target directory.
You can control when a jar is built with something like this: jar { onlyIf { condition } } You can set jar to be built when you declare something else to be true, or hard set it to false to never build a jar. You can include sourcesets in your toJar custom task, to include compiled files into your jar.
main. runtimeClasspath' contains the compiled classes of the source set, and task autowiring automatically adds the necessary task dependencies. Maybe you want 'sourceSets. main. compileClasspath'.
With the latest Gradle version 6.0.1, there seems to be no way to use these new methods in Android library projects. Here’s why I believe that’s the case:
The two methods withJavadocJar()
and withSourcesJar()
on the java
extension have the default main
source set hardcoded, see here and here.
There are two methods with the same names (withJavadocJar()
and withSourcesJar()
) which can be used in feature variant declarations. However, it seems that Android Gradle builds don’t use feature variants, i.e., these methods can’t be used either.
The documentation states, that these come from the JavaPluginExtension - but not from Android DSL. So they can only be used in conjunction with apply plugin: "java"
or apply plugin: "java-library"
, but not with apply plugin: "com.android.application"
, apply plugin: "com.android.library"
and alike. The name of these tasks also suggest that it's common Java (*.jar
) and not Android (*.aar
). On Android, this would only make sense for a *.jar
library, which uses pure Java features, but no Android features at all (which is limited in functionality).
In short, apply plugin: "java-library"
would permit accessing these.
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