android - 使用产品口味的重复类

标签 android gradle android-flavors android-flavordimension

我的Android gradle版本有很多味道。
其中之一具有包含重复依赖项(a.com.google.zxing)的aar文件。

build.gradle:

...
dependencies {
    implementation 'com.google.zxing:core:3.3.3'
    implementation 'me.dm7.barcodescanner:zxing:1.9.8'
    // Standard flavour
    standardImplementation(name: 'libgedi-0.190121.gpos800', ext: 'aar') {
        exclude group: 'com.google.zxing', module: 'android-core'
        transitive = false
    }
    ...
}

对于“标准”构建,此配置产生以下内容(适用于其他口味):
    Duplicate class com.google.zxing.BarcodeFormat found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos800:)
    Duplicate class com.google.zxing.Binarizer found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos800:)
    Duplicate class com.google.zxing.BinaryBitmap found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos800:)
    Duplicate class com.google.zxing.ChecksumException found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos8
    ...

我试图将配置更改为:
    standardImplementation(name: 'libgedi-0.190121.gpos800', ext: 'aar') {
        configurations {
            all*.exclude group: 'com.google.zxing'
        }
    }

上面的配置仅在我构建“标准” flavor 时才有效。换一种说法,会发生此错误:
error: package com.google.zxing.qrcode.decoder does not exist

我做错了什么?

最佳答案

解:

{
    configurations {
        exclude group: 'com.google.zxing'
    }
}

使用排除代替所有*排除

关于android - 使用产品口味的重复类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58648403/

相关文章:

java - 从静态方法更改非静态值

java - Android Studio 中的 Gradle 构建失败

android - flavor 特定代码

android - 无法在 Flutter 中构建具有多种风格的发布 apk?

android - Android风格的多个正交轴

安卓内存管理

android - 如何保持 session

android - Google Play服务已过时。需要9683000但找到9452230

android - 标题 : self signing server certificate

android-studio - “Duplicate Zip Entry”(来自Proguard)-renderscript-v8.jar