Replace the deprecated packagingOptions block in an Android build file
packagingOptions is deprecatedShort answer
The Android Gradle plugin renamed the packagingOptions block to packaging. Inside it, the old top-level exclude, pickFirst, merge and doNotStrip entries are deprecated too. Move Java resource patterns to packaging.resources and .so patterns to packaging.jniLibs, using excludes, pickFirsts, merges or keepDebugSymbols.
Fix it fast
1Find out which cause you have
Find every packagingOptions block and every call inside it, so you can sort each pattern into Java resources or native libraries.
grep -rn -A8 'packagingOptions' --include=build.gradle --include=build.gradle.kts .2Match what you see, then jump to its fix
What does the error look like?
packagingOptions is deprecatedpackagingOptions(action: Packaging.() -> Unit) is deprecated: Renamed to packaging
Cause 1 of 2
The block is still called packagingOptions
1Check
In the Android DSL reference, packagingOptions is marked deprecated with the note that it was renamed to packaging.
grep -rn 'packagingOptions' --include=build.gradle --include=build.gradle.kts .2Fix
Rename the block. The nested settings keep working while you move them in the next cause.
android {
packaging {
// settings go here
}
}3Verify
Sync the project. The warning on the block name is gone.
./gradlew helpConfirmed by developer.android.com
Cause 2 of 2
Patterns still sit directly in the block
1Check
Per the Packaging reference, these entries are deprecated since 8.0.2. Java resource patterns belong to resources, and .so file patterns belong to jniLibs.
grep -rn -E 'exclude|pickFirst|merge|doNotStrip' --include=build.gradle.kts .2Fix
Sort each pattern by file type and use the new property sets.
android {
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
pickFirsts += "META-INF/INDEX.LIST"
}
jniLibs {
pickFirsts += "**/libc++_shared.so"
keepDebugSymbols += "**/libfoo.so"
}
}
}3Verify
Build the variant that used to report duplicate files.
./gradlew :app:assembleDebugConfirmed by developer.android.com
How do I stop it coming back?
- Put new exclusions straight into packaging.resources or packaging.jniLibs.
- Review deprecation warnings when you raise the Android Gradle plugin version.
- Keep one pattern per line with a comment saying which library caused it.
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
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
Android build fails because two libraries ship the same META-INF file
More than one file was found with OS independent path
Two dependencies put a file at the same path inside the APK and the plugin will not guess which one wins.
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