gpt4 book ai didi

android - 包含带有 android flavor 的库

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:43:50 24 4
gpt4 key购买 nike

我之前的应用程序 gradle 文件:

编译工程(路径: ':zblelib')

但是当我将口味添加到库中时,我的导入不起作用

我的口味:

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 中添加 flavor (+ 维度):

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')
}

这样,当你选择应用的 flavor nocustomer时,库的 flavor 会自动选择nocustomer,当你选择应用的 flavor 时customerNb,库的flavor会自动选择customer001

附言

我正在使用 implementation 而不是 compile,因为不推荐使用 compile ( see here )

关于android - 包含带有 android flavor 的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49815655/

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