AboutLibraries icon indicating copy to clipboard operation
AboutLibraries copied to clipboard

Adding `tasks.whenTaskAdded` breaks the output-metadata.json generation

Open aminecmi opened this issue 9 months ago • 9 comments

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")
     }*/

aminecmi avatar Mar 20 '25 13:03 aminecmi

I have the same issue

FricoRico avatar Mar 24 '25 07:03 FricoRico

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?

mikepenz avatar Mar 28 '25 08:03 mikepenz

Can you please provide a minimal reproducible example for this?

mikepenz avatar Mar 28 '25 12:03 mikepenz

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

FricoRico avatar Mar 31 '25 10:03 FricoRico

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.

btrautmann avatar Jun 06 '25 17:06 btrautmann

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!

btrautmann avatar Jun 06 '25 18:06 btrautmann

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.

mikepenz avatar Jun 07 '25 08:06 mikepenz

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.

Image

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

mikepenz avatar Jun 07 '25 09:06 mikepenz

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.

mikepenz avatar Jul 11 '25 16:07 mikepenz