Adding `tasks.whenTaskAdded` breaks the output-metadata.json generation
Hello,
My app uses the legacy view based UI, and it worked great until I added a tasks.whenTaskAdded {} block in my build.gradle.kts file.
Since then, the view is blank, and the logcat reads
E Invalid resource ID 0x00000000.
E Unable to retrieve library information given the `raw` resource identifier.
E Please make sure either the gradle plugin is properly set up, or the file is manually provided.
I Could not retrieve libraries
E Unable to read the library information
java.lang.IllegalStateException: Please provide the required library data via the available APIs.
Depending on the platform this can be done for example via `LibsBuilder().withJson()`.
For Android there exists an `LibsBuilder.withContext()`, automatically loading the `aboutlibraries.json` file from the `raw` resources folder.
When using compose or other parent modules, please check their corresponding APIs.
at com.mikepenz.aboutlibraries.Libs$Builder.build(Libs.kt:44)
at com.mikepenz.aboutlibraries.viewmodel.LibsViewModel$listItems$1$1.invokeSuspend(LibsViewModel.kt:100)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
I tried tinkering with the gradle file, but this does not change anything.
Is there a fix for this ?
This is what I tried. Using taskTree plugin, the output of both with and without seemed the same, but the issue stayed the same.
tasks.whenTaskAdded {
// MY CODE HERE
/* if (this.name == "mergeGithubConfigDebugResources" ||
this.name == "packageGithubConfigDebugResources" ||
this.name == "mapGithubConfigDebugSourceSetPaths" ||
this.name == "extractDeepLinksGithubConfigDebug"
) {
this.dependsOn("prepareLibraryDefinitionsGithubConfigDebug")
}*/
I have the same issue
Good day.
I am not familiar with the whenTaskAdded. Do you have some additional details of why you need to do that?
Do other similar libraries generating data have similar issues with whenTaskAdded?
Can you please provide a minimal reproducible example for this?
I have found out I do not need to rely on whenTaskAdded. I copied the EspeakNG Android example which packages languages into a ZIP file when building the project and puts it in res/raw. But it turns out I do not need whenTaskAdded for this.
See ESpeakNG project: https://github.com/espeak-ng/espeak-ng/blob/master/android/build.gradle#L112
I ran into this myself and I'm really glad I found this issue or I would've had no clue this was indeed the root cause. To ensure it wasn't just a "me" thing, I started a new Android project (albeit using Flutter).
This was simply created via flutter create -e, which creates a basic empty project.
Here's the repo: https://github.com/btrautmann/about-libraries-repro. Specifically, I just added a whenTaskAdded block that prints the names of task if it contains a certain String. As soon as I added this block, the project no longer compiles. When that's removed, it builds and you can see the log statement from MainActivity that prints the number of libraries found.
Ultimately, I was only trying to add dependsOn configuration to various tasks, so I did this via applicationVariants.all { .. } and I was able to work around this, but was totally unexpected!
Thank you for the repo. I've spent some time trying to find a solution for this problem, however I've not found none yet.
If someone has suggestions on a proper way to resolve this problem, I'd be happy to have a try.
So I spent more time on it, things from the AboutLibraries side seem to be registered and built properly.
But I think the follow up part of providing the built resources to the android tasks seems to maybe be the problem.
As such my advice here would be:
- Disable the android task
aboutLibraries {
android {
registerAndroidTasks = true
}
}
- Build the library definition file with the respective task
- include the resource as such in the project.
- https://github.com/mikepenz/AboutLibraries?tab=readme-ov-file#enterprise--manual-json-handling
Can you please test the new alpha version? it splits the plugin into 2 components. the main plugin with the manual tasks, and then the secondary android plugin. I wonder if now with the android registration removed by default this starts working.