Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Android build fails because two libraries ship the same META-INF file

Error2 files found with path 'META-INF/NOTICE.md'

Short answer

Two dependencies put a file at the same path inside the APK and the plugin will not guess which one wins. Tell the plugin what to do for that path in the packaging block: exclude it, keep the first copy, or merge the copies. Pick by what the file is, not by which line makes the error stop.

  • Applies to Android Gradle plugin 8.x and 9.x, Gradle 8.x and 9.x, Kotlin DSL
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run the build that failed and read the message in full. The path in single quotes is the exact entry that collides. Then list the libraries on the classpath, so you know which ones could be shipping it.

    ./gradlew :app:assembleDebug
    ./gradlew :app:dependencies --configuration debugRuntimeClasspath
  2. 2Match what you see, then jump to its fix

    1. 1The colliding path is a documentation file such as META-INF/NOTICE.md, not a file the code readsThe duplicate is a notice or licence text the APK does not need to carryFix
    2. 2Excluding the path fixes the build, but a licence screen or a library you ship expects the file to be presentYou need exactly one copy of the file in the APKFix
    3. 3The colliding file is a list or registry (for example a file under META-INF/services), and the app misbehaves at runtime once one copy is droppedBoth copies hold content that has to be keptFix

What does the error look like?

  • 2 files found with path 'META-INF/NOTICE.md'
  • More than one file was found with OS independent path

Cause 1 of 3

The duplicate is a notice or licence text the APK does not need to carry

1Check

Look at the name in the message. A NOTICE or LICENSE file is documentation, not code. The Android DSL says Java resources that match an excludes pattern do not get packaged in the APK, so confirm first that your app does not read this file itself.

grep -rn -B1 -A6 "packaging" --include=build.gradle --include=build.gradle.kts .

2Fix

Add the path to excludes in the app module. The pattern in the Android DSL sample starts with a slash.

// app/build.gradle.kts
android {
    packaging {
        resources {
            excludes += "/META-INF/NOTICE.md"
        }
    }
}

3Verify

Rebuild, then confirm that the entry is no longer inside the APK.

./gradlew :app:assembleDebug
unzip -l app/build/outputs/apk/debug/app-debug.apk | grep "META-INF/NOTICE.md"

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 3

You need exactly one copy of the file in the APK

1Check

If your app shows open-source notices from this file, dropping it removes it for every library. The Android DSL lets you keep the first occurrence instead: for each matching path, only the first Java resource found is packaged.

grep -rn "NOTICE" --include=*.kt --include=*.java app/src

2Fix

Use pickFirsts for that path, not excludes.

android {
    packaging {
        resources {
            pickFirsts += "/META-INF/NOTICE.md"
        }
    }
}

3Verify

Rebuild and check that exactly one entry with that name is in the APK.

./gradlew :app:assembleDebug
unzip -l app/build/outputs/apk/debug/app-debug.apk | grep "META-INF/NOTICE.md"

Confirmed by developer.android.com

Did this fix it?

Cause 3 of 3

Both copies hold content that has to be kept

1Check

Keeping only one copy of a file that each library contributes lines to loses the other library's entries. Open the colliding file from each library's jar to see whether the contents differ.

./gradlew :app:dependencies --configuration debugRuntimeClasspath

2Fix

Use merges. For each APK entry path that matches, the plugin concatenates all Java resources with that path into one entry.

android {
    packaging {
        resources {
            merges += "/META-INF/services/example.Service"
        }
    }
}

3Verify

Build, then run the feature that depends on that registry.

./gradlew :app:assembleDebug

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Make the decision per path: exclude text you do not need, pick one copy of what you must show, merge registries.
  • Do not exclude broad patterns such as everything under META-INF to silence one file; a wide pattern can drop a file that a library needs.
  • Re-check the packaging block after each dependency upgrade, because a new library can bring a new colliding path.
  • Put the packaging rules in the app module only, since that is where the APK is assembled.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.