我的应用程序gradle文件之前:
编译项目(路径:': 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')
}
app
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 {
? ?
}
该应用程序的问题是它不知道使用哪个库的风格。
关键字matchingFallback
将告诉应用程序您要选择哪个库的风格。但是这个关键字必须与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')
}
这样,当您选择应用的风味no客户
时,库的风味会自动选择no客户
,当您选择应用的风味客户Nb
时,库的风味会自动选择客户001
PS
我使用实现
而不是编译
,因为编译已被弃用(见此处)
您应该在应用程序的build. gradle
文件中使用missingDimensionStrategy
,它与库中缺少的风格相匹配。检查Gradle 3.0.0的迁移文档如何实现它。
对于您的库包含应用程序不包含的产品风格的特定问题,检查部分库依赖项包含您的应用程序不包含的风格维度。
从表中。
编辑:在应用程序的build. gradle
文件中定义风格,然后使用matchingFallback
从库中准确指定要匹配的风格。
productFlavors {
paid {
dimension 'tier'
matchingFallbacks = ['customer001', 'nocustomer']
}
free {
dimension 'tier'
matchingFallbacks = ['nocustomer', 'customer001']
}
}
我应该另一种方式来实现这一点:
首先添加一个风格和维度到您的应用程序build. gradle
哪个gradle id是com.android.application
,如下所示:
plugins {
id 'com.android.application'
}
android {
resourcePrefix "app_"
flavorDimensions "env"
productFlavors {
dev {
dimension "env"
}
pre{
dimension "env"
}
prod {
dimension "env"
}
}
}
然后将以下代码片段添加到您的库模块中
plugins {
id 'com.android.library'
}
android {
resourcePrefix "base_"
flavorDimensions "env"
productFlavors {
register("dev")
register("pre")
register("prod")
}
}