Android build fails because two libraries ship the same META-INF file
2 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.
Fix it fast
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 debugRuntimeClasspath2Match what you see, then jump to its fix
- 1
The 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
Excluding 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
The 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
- 1
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
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/src2Fix
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
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 debugRuntimeClasspath2Fix
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:assembleDebugConfirmed by developer.android.com
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:
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Nuclear Home VideoA video-streaming Android app built from scratch, engineered for smooth playback.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
Replace the deprecated packagingOptions block in an Android build file
packagingOptions(action: Packaging.() -> Unit) is deprecated: Renamed to packaging
The Android Gradle plugin renamed the packagingOptions block to packaging.
2 causes, each with a fixMobile apps
Android build fails because a product flavor has no flavor dimension
The flavor 'flavor_name' is not assigned to a flavor dimension.
Android Gradle plugin refuses to build when a product flavor is not assigned to a flavor dimension.
2 causes, each with a fixMobile apps
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning on FirebaseInstanceId.getInstance().getToken()
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes.
2 causes, each with a fix