问题描述
我的应用gradle文件之前:
My app gradle file before:
编译项目(路径:':zblelib')
但是当我在lib中添加口味时,我的导入无法正常工作
But when i add flavors into the lib my import don't work
我的口味:
flavorDimensions "dim"
productFlavors {
nocustomer {
versionNameSuffix "-nocustomer"
dimension = "dim"
}
customer001 {
versionNameSuffix "-customer001"
dimension = "dim"
}
}
我如何选择口味导入新库?
how can i import my new library with choice of flavor?
我的build.gradle
edit: my build.gradle
图书馆
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 18
targetSdkVersion 26
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "dim"
productFlavors {
nocustomer {
versionNameSuffix "-nocustomer"
dimension = "dim"
}
customer001 {
versionNameSuffix "-customer001"
dimension = "dim"
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:27.1.1'
compile 'com.android.support:design:27.1.1'
compile 'com.android.support:support-v4:27.1.1'
compile project(':criptolib-debug')
}
应用
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultPublishConfig "nocustomerRelease"
defaultConfig {
applicationId "com.axesstmc.bleappphone"
minSdkVersion 18
targetSdkVersion 26
versionCode 91
versionName "8.2"
}
buildTypes {
debug {
minifyEnabled false
//proguardFiles 'proguard-rules.pro'
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
? ?
}
推荐答案
应用程序存在的问题是它不知道使用哪种库的样式.
The problem the app has is that it doesn't know which library's flavor to use.
关键字 matchingFallbacks
会告诉应用您要选择哪种库的样式.但是此关键字必须与Flavor一起使用.
The keyword matchingFallbacks
will tell the app which library's flavor you want to select. But this keyword has to be use with a Flavor.
我们必须在您的应用程序build.gradle上添加风味(+尺寸):
We have to add a flavor (+ dimension) on your app build.gradle:
android {
...
//flavorDimensions is mandatory with flavors. Use the same name on your 2 files to avoid other conflicts.
flavorDimensions "dim"
productFlavors {
nocustomer{
dimension "dim"
// App and library's flavor have the same name.
// MatchingFallbacks can be omitted
matchingFallbacks = ["nocustomer"]
}
customerNb{
dimension "dim"
// Here the app and library's flavor are different
// Matching fallbacks will select the library's flavor 'customer001'
matchingFallbacks = ["customer001"]
}
}
...
}
dependencies {
implementation project(':zblelib')
}
通过这种方式,当您选择应用程序的风味 nocustomer
时,库的风味将自动选择 nocustomer
,并且当您选择应用程序的风味 customerNb 代码>,库的样式将自动选择
customer001
In this way, when you select the app's flavor nocustomer
, the library's flavor will select automatically nocustomer
, and when you select the app's flavor customerNb
, the library's flavor will select automatically customer001
PS
我使用的是 implementation
而不是 compile
,因为不建议使用compile(请参阅此处)
I am using implementation
instead of compile
, because compile is deprecated (see here)
这篇关于包含带有风味android的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!