Maaz Zindani

Loading the index…

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

Replace the deprecated packagingOptions block in an Android build file

ErrorpackagingOptions is deprecated

Short 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.

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

Fix it fast

  1. 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 .
  2. 2Match what you see, then jump to its fix

    1. 1A deprecation warning on packagingOptions in the module build fileThe block is still called packagingOptionsFix
    2. 2Deprecation warnings on exclude, pickFirst, merge or doNotStrip, or on the excludes, pickFirsts, merges, doNotStrip propertiesPatterns still sit directly in the blockFix

What does the error look like?

  • packagingOptions is deprecated
  • packagingOptions(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 help

Confirmed by developer.android.com

Did this fix it?

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:assembleDebug

Confirmed by developer.android.com

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

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