我的应用级 build.gradle 文件定义了多种产品风格。我只需要为产品口味的组合添加依赖项。
我的 gradle 风格是:
flavorDimensions "generic", "custom"
productFlavors {
clover {
dimension "custom"
minSdkVersion 17
}
ga {
dimension "custom"
minSdkVersion 21
}
dit {
dimension "generic"
applicationIdSuffix ".dit"
resValue "string", "app_name", "ADP Time DIT"
}
fit {
dimension "generic"
applicationIdSuffix ".fit"
resValue "string", "app_name", "ADP Time FIT"
}
iat {
dimension "generic"
applicationIdSuffix ".iat"
resValue "string", "app_name", "ADP Time IAT"
}
prodqa {
dimension "generic"
resValue "string", "app_name", "ADP Time QA"
}
prod {
dimension "generic"
resValue "string", "app_name", "ADP Time"
}
}
现在,我只需要“com.google.firebase:firebase-core:16.0.5”用于 gaDit、gaFit、gaIat、gaProd、gaProdqa 风格。 我的依赖项部分是:
dependencies {
implementation project(':react-native-background-task')
implementation "com.android.support:appcompat-v7:26.1.0"
implementation 'com.android.support:multidex:1.0.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
/*changed to accommodate TLSv1 issue. could remove after the issue is fixed in react native*/
// implementation 'com.facebook.react:react-native:+'
implementation project(':react-native-android')
implementation project(':lottie-react-native')
implementation project(':react-native-config')
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
fitGaImplementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
implementation project(':react-native-device-info')
implementation project(':react-native-background-timer')
implementation project(':realm')
implementation project(':react-native-code-push')
// From node_modules
implementation 'com.facebook.fresco:animated-gif:1.10.0'
implementation files('libs/dpuareu.jar')
implementation files('libs/gson-2.8.1.jar')
}
但是,我在构建时遇到了问题,提示找不到“FirebaseInstanceId”。
如何根据产品口味为构建变体组合添加依赖项?
最佳答案
为了能够在依赖中使用flavors的组合,你需要添加
configurations {
fitGaImplementation {}
}
到您应用的 gradle。
在the docs你可以看到
"if you want to add a dependency for a variant that combines a product flavor and a build type, then you must initialize the configuration name in the configurations block. ..."
关于android - 为不同的产品口味组合添加依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53651489/