android - 为不同的产品口味组合添加依赖

标签 android react-native gradle

我的应用级 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/

相关文章:

android - 构建Android时如何保存所有中间文件?

android - Google Playstore 中的零支持设备(支持的设备部分)

android - 如何使用Viewpager和Fragment分割窗口?

java - 从另一个类覆盖 Activity 对象的 onActivityResult

android - Gif 图像在 react 原生的 android 中不起作用

android - AppCenter React Native Android 构建失败无法下载 groovy-all-2.4.15.jar (org.codehaus.groovy :groovy-all:2. 4.15)

swift - 在 OSX 或 Windows (VM)、React Native 还是 Swift 上进行 iOS 开发?

gradle - 是否可以将 apollo-android v2 与 Gradle 5 一起使用?

android - 添加库后,Android Studio中的构建失败

java - Gradle 给出错误 :(16, 0) 找不到参数的方法 SourceSet()