gpt4 book ai didi

android - 为每个 android 风格使用不同的库模块

转载 作者:搜寻专家 更新时间:2023-11-01 07:41:46 26 4
gpt4 key购买 nike

我想为每种风格使用不同的库模块。

例如:

  • free flavor -> 我需要使用 free library 模块
  • paid flavor -> 我需要使用付费库模块

我的口味

productFlavors {
free{
.......
}
paid{
.......
}
}

我尝试过的

freeImplementation  project(path:':freeLib', configuration: 'free')//for free

paidImplementation project(path:':paidLib', configuration: 'paid')//for paid

但是我遇到编译错误无法使用这个

注意:这不是一个重复的问题。我已经尝试了一些 StackOverflow 问题。它已经过时了(他们正在使用编译)

引用 - Multi flavor app based on multi flavor library in Android Gradle

解决方案(来自 Gabriele Mariotti 的评论)

 freeImplementation project(path:':freeLib')
paidImplementation project(path:':paidLib')

最佳答案

如果您有一个包含多种产品风格的库,您可以在 lib/build.gradle 中定义:

android {
...
//flavorDimensions is mandatory with flavors.
flavorDimensions "xxx"
productFlavors {
free{
dimension "xxx"
}
paid{
dimension "xxx"
}
}
...
}

在你的 app/build.gradle 中定义:

android {
...

flavorDimensions "xxx"
productFlavors {
free{
dimension "xxx"

// App and library's flavor have the same name.
// MatchingFallbacks can be omitted
matchingFallbacks = ["free"]
}
paid{
dimension "xxx"

matchingFallbacks = ["paid"]
}
}
...
}
dependencies {
implementation project(':mylib')
}

相反,如果你有单独的库,你可以简单地在你的 app/build.gradle 中使用像这样的东西:

dependencies {
freeImplementation project(':freeLib')
paidImplementation project(':paidLib')
}

关于android - 为每个 android 风格使用不同的库模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56372539/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com