2

My Android app is not building.

The funny thing is that it suggests me:

Adding a packaging block may help, please refer to

And if I add packaging then it fails again and suggests to add packagingOptions, so it's driving me nuts, don't know if it is expecting packaging or packagingOptions, but anyway none of them seem to work.

This was my initial packagingOptions section:

packagingOptions {
        resources {
            pickFirsts += ['META-INF/LICENSE.txt']
            excludes += ['META-INF/NOTICE.md', 'META-INF/LICENSE.md', 'META-INF/INDEX.LIST', 'META-INF/DEPENDENCIES', 'META-INF/io.netty.versions.properties']
        }
    }

Not working, and next is my current build.gradle (the commented code are all the combinations I've tried):

android {
    ...
    packaging {
        resources {
            resources.excludes.add("META-INF/NOTICE.md")
            resources.excludes.add("META-INF/LICENSE.md")
            resources.excludes.add("META-INF/INDEX.LIST")
            resources.excludes.add("META-INF/DEPENDENCIES")
            resources.excludes.add("META-INF/io.netty.versions.properties")

            /*pickFirsts += ['META-INF/LICENSE.txt']
            excludes += ['META-INF/NOTICE.md', 'META-INF/LICENSE.md', 'META-INF/INDEX.LIST', 'META-INF/DEPENDENCIES', 'META-INF/io.netty.versions.properties']*/
        }
        //resources.excludes.add("META-INF/*")
    }
  ...
}

I've already migrated gradle to latest 8.5 version with the assistant (and, just in case, also updated all libraries).

Of course I've already checked all SO similar threads before posting, but none of them helped me.

It was working in the past, but after some update -not sure what- it stopped working.

Now with a packaging block correctly set it complains:

Adding a packaging block may help, please refer to

What? I already have a packaging block inside android {} block.

BTW: The help

https://developer.android.com/reference/tools/gradle-api/8.0/com/android/build/api/dsl/ResourcesPackagingOptions#excludes()

does not help.

What to try next?

1 Answer 1

0

After inspecting the build log in detail I found that the "META-INF/NOTICE.md" file that was making gradle to complain was in this next two packages:

com.sun.mail:android-mail:1.6.7
com.sun.mail:android-activation:1.6.7

I remember I'm using this packages for email sending inside the app, but decided to comment android-activation to test if the build would still complains, and to my surprise it was still complaining.

What, I asked to myself, how it can be possible that META-INF/NOTICE.md is still repeated when I disabled one of the packages?

It ended being that there was a cached jar file jetified-android-activation-1.6.7.jar in the following folder:

/Users/myname/.gradle/caches/transforms-4/cdb8986a59c9b6d77240a4c4c934fcba/transformed/

I cannot understand how after a "Clean Project" and commenting that package in build.gradle such file was still present, but after renaming the file the build succeeded.

That weird things we, developers, has to deal with so often...

I don't yet understand why the app still builds having commented com.sun.mail:android-activation, because I was sure that package was used -along with com.sun.mail:android-mail- for email sending, but the fact is that it is not only building correctly, but also sending emails with no problems.

I have to end saying this is not a solution, it was a solution for me in the sense it allowed me to build and run, but the solution would be to know why packagingOptions is not working at all when it is supposed to, and not to be forced to remove a package from gradle, so if anyone could expand this solution with a more general one it would be welcome.

Edit 1: This answer it is not useful in the end.

Even I delete the file jetified-android-activation-1.6.7.jar it is being created over and over again from time to time when building the app, and I cannot understand why, because I remove the package from build.gradle.

I'm stuck again and really need to know why excludes in packagingOptions is not working.

Not the answer you're looking for? Browse other questions tagged or ask your own question.