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}')
2
Answers
It doesn’t say
packaginOptions
is deprecated:https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/PackagingOptions
https://developer.android.com/reference/tools/gradle-api/8.0/com/android/build/api/dsl/PackagingOptions
It says
excludes
is deprecated:It’s interesting that the 7.0 docs include
excludes
(https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/PackagingOptions#excludes:kotlin.collections.MutableSet).7.2 only has
exclude
(https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/dsl/PackagingOptions#exclude(kotlin.String)) but explains what to swap it with:Which is what you’ve done.
If you read the 8.0 docs and click through to
resources.excludes
https://developer.android.com/reference/tools/gradle-api/8.0/com/android/build/api/dsl/ResourcesPackagingOptions#excludes()It gives an example:
So you could try that. (which is looks like you have).
Are you sure its highlighted as deprecated, and not highlighted as
incubating
as written here in the 8.0 docs? https://developer.android.com/reference/tools/gradle-api/8.0/com/android/build/api/dsl/PackagingOptionsThis Method is Deprecated, this is doc
old:
replace: