【问题标题】:Gradle dependencies based on multi flavorDimensions基于多风味维度的 Gradle 依赖项
【发布时间】:2021-11-10 15:20:06
【问题描述】:

我在一个 Android 项目中有以下风味配置:

android {
    buildTypes {
        release { }
        debug { }
    }

    flavorDimensions "fruit", "color" 

    productFlavors {
        apple { 
            dimension "fruit"
        }
        peach { 
            dimension "fruit"
        }
        banana {
            dimension "fruit"
        }

        red {
            dimension "color" 
        }
        green {
            dimension "color" 
        }
        yellow {
            dimension "color" 
        }
    }
}


dependencies {
    appleRedImplementation 'com.apple:color_red:1.1.0'
    appleGreenImplementation 'com.apple:color_green:1.1.0'
    appleYellowImplementation 'com.apple:color_yellow:1.1.0'
    // No dependency for other fruit build type 
}

我需要为appleflavorDimensions 构建保留com.apple:color_*:1.1.0 依赖only,但根据colorflavorDimensions 构建对其进行更改?

【问题讨论】:

  • 我不明白你的问题是什么。你能详细说明吗?您的解决方案看起来是正确的。
  • @AlexanderHoffmann appleRedImplementation 不存在并且应用程序不构建,只有 appleImplementation 存在(单一的 flavorDimension,而不是两者的组合)。所以我想知道是否有一种解决方法可以根据fruit+color flavorDimensions 组合添加依赖项。

标签: android gradle


【解决方案1】:

如果您想为多个构建风格维度的特定配置添加依赖项,您需要先定义这些组合:

android{
    ...
    productFlavors {
        ...
    }
    configurations {
        appleRedImplementation {}
        appleGreenImplementation {}
        appleYellowImplementation {}
    }
}

这里的答案也引用了这个:https://stackoverflow.com/a/60776044/2258611

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    • 2017-02-06
    • 1970-01-01
    • 2014-04-14
    • 1970-01-01
    相关资源
    最近更新 更多