I've custom annotation processor generating factory classes and META-INF/services/factory.interface.class
resource.
Annotation processor is used in library project and all generated files are packaged correctly into AAR.
When I use annotation processor in application project with library added as a dependency only classes from libraries META-INF/services/factory.interface.class
exist in APK/META-INF/services/factory.interface.class
After some investigation I realized that MergeJavaResourcesTransform
in android-gradle-plugin-1.5.0 (and 2.0.0-alpha3) looks for resources for merging in all exploded-aar
s, jar
s, and intermediates/sourceFolderJavaResources
Is there any way to merge META-INF
from intermediates/classes
(it's where resource files from annotation processor get created) or make annotation processor create file in sourceFolderJavaResources
?
Only workaround I've found so far is to add CopyTask
in application's buildscript
android.applicationVariants.all { variant ->
def variantName = variant.name
def variantNameCapitalized = variantName.capitalize()
def copyMetaInf = tasks.create "copyMetaInf$variantNameCapitalized", Copy
copyMetaInf.from project.fileTree(javaCompile.destinationDir)
copyMetaInf.include "META-INF/**"
copyMetaInf.into "build/intermediates/sourceFolderJavaResources/$variantName"
tasks.findByName("transformResourcesWithMergeJavaResFor$variantNameCapitalized").dependsOn copyMetaInf
}
But I do not wat to force compiler an library users do do anything more than adding dependencies.
Annotation processing is a powerful tool for generating code for Android apps. In this tutorial, you'll create one that generates RecyclerView adapters.
Annotation Processing APIEach annotation processor, in turn, is called on the corresponding sources. If any files are generated during this process, another round is started with the generated files as its input. This process continues until no new files are generated during the processing stage.
Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors -> Enable Annotation Processing.
Annotations allow you to provide hints to code inspections tools like Lint, to help detect these more subtle code problems. They are added as metadata tags that you attach to variables, parameters, and return values to inspect method return values, passed parameters, local variables, and fields.
It seems that the issue is related to META-INF folder. Here is the bug reported for Service Loader and META-INF
By the way, there is a confirmed solution:
Also, you may want to check the following questions on SO:
Initial Answer:
You might want to try to configure your library source set's resources
attribute (with your location of META-INF/services) which is responsible for:
The Java resources which are to be copied into the javaResources output directory.
Here is an example:
android {
...
sourceSets {
main {
resources.srcDirs = ['/src/META_INF_generated']
}
}
...
}
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