Ran*_*mar 9 android gradle android-gradle-plugin android-flavors
我想为每种风格使用不同的库模块。
例如:
我的口味
productFlavors {
free{
.......
}
paid{
.......
}
}
Run Code Online (Sandbox Code Playgroud)
我试过的
freeImplementation project(path:':freeLib', configuration: 'free')//for free
paidImplementation project(path:':paidLib', configuration: 'paid')//for paid
Run Code Online (Sandbox Code Playgroud)
但是我得到了编译错误无法使用这个
注意:这不是一个重复的问题。我已经尝试过一些 StackOverflow 问题。它已经过时了(他们正在使用编译)
参考 -基于 Android Gradle 中多风格库的多风格应用
解决方案(来自 Gabriele Mariotti 评论)
freeImplementation project(path:':freeLib')
paidImplementation project(path:':paidLib')
Run Code Online (Sandbox Code Playgroud)
Gab*_*tti 16
如果您有一个包含多种产品口味的库,lib/build.gradle您可以在其中定义:
android {
...
//flavorDimensions is mandatory with flavors.
flavorDimensions "xxx"
productFlavors {
free{
dimension "xxx"
}
paid{
dimension "xxx"
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
在您的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')
}
Run Code Online (Sandbox Code Playgroud)
相反,如果你有单独的库,你可以简单地在你的app/build.gradle东西中使用:
dependencies {
freeImplementation project(':freeLib')
paidImplementation project(':paidLib')
}
Run Code Online (Sandbox Code Playgroud)
首先将以下 gradle 代码片段添加到您的app/build.gradle
flavorDimensions "env"
productFlavors {
dev {
dimension "env"
}
pre {
dimension "env"
}
prod {
dimension "env"
}
}
Run Code Online (Sandbox Code Playgroud)
其次,将以下 gradle 代码片段添加到您的module/build.gradle
flavorDimensions "env"
productFlavors {
register("dev")
register("pre")
register("prod")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3419 次 |
| 最近记录: |