I have migrated to gradle 8 my android build gradle files show
plugins {
id 'com.android.application' version '8.1.0-alpha01' apply false
id 'com.android.library' version '8.1.0-alpha01' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
id 'com.google.dagger.hilt.android' version '2.44.2' apply false
}
tasks.register('clean') {
delete rootProject.buildDir
}
Now in my module gradle.build files packagingOptions is highlighted as deprecated
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}

I thought I had found this solution
packagingOptions {
resources.excludes.add('/META-INF/{AL2.0,LGPL2.1}')
}
which does not work!!! what is the correct replacement for the deprecated packagingOptions exclude?
The version of android studio I am using is
Android Studio Giraffe | 2022.3.1 Canary 1
Build #AI-223.4884.69.2231.9486165, built on January 13, 2023
Runtime version: 17.0.5+0-17.0.5b653.23-9410051 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.6.1
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 12
Metal Rendering is ON
Registry:
external.system.auto.import.disabled=true
ide.text.editor.with.preview.show.floating.toolbar=false
ide.images.show.chessboard=true
Non-Bundled Plugins:
com.android.aas (3.5.1)
This appears to fix it
packagingOptions.resources.excludes.add('/META-INF/{AL2.0,LGPL2.1}')
This Method is Deprecated, this is doc
@Deprecated("Renamed to packaging", replaceWith = ReplaceWith("packaging"))
fun packagingOptions(action: Packaging.() -> Unit)
val packaging: Packaging
fun packaging(action: Packaging.() -> Unit)
old:
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
replace:
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
In Kotlin AGP 8.0 I just prefixed exludes with it and the deprecation warning is now gone.
packaging {
resources {
it.excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}


If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With