我的应用程式gradle档案之前:
compile project(path: ':zblelib')
但是当我在lib中添加口味时,我的导入不起作用
我的口味:
flavorDimensions "dim"
productFlavors {
nocustomer {
versionNameSuffix "-nocustomer"
dimension = "dim"
}
customer001 {
versionNameSuffix "-customer001"
dimension = "dim"
}
}
如何选择口味导入新库?
编辑:我的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 {
? ?
}
应用程序存在的问题是,它不知道要使用哪个库的样式。
关键字matchingFallbacks
将告诉应用程序您要选择哪种库的样式。但是此关键字必须与Flavor一起使用。
我们必须在您的应用程序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
聚苯乙烯
我使用implementation
而不是compile
,因为不建议使用compile(请参见此处)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句