How to apply plugin to only one flavor in gradle?

前端 未结 5 795
我寻月下人不归
我寻月下人不归 2020-12-01 07:27

I have a multi-flavored, multi-build-typed android project and I want to integrate the NewRelic plugin. But I have to apply it only for one of the customers, thus only for o

5条回答
  •  日久生厌
    2020-12-01 07:54

    Tried different solutions, but none of them worked for me. This is what I came up with and seems to work as far as I tested:

    build.gradle

    productFlavors {
        someFlavorWithGoogleGcm {
            dimension "type"
            applicationId "com.example.withGcm"
            ext.useGoogleGcm = true
        }
        someFlavorWithoutGoogleGcm {
            dimension "type"
            applicationId "com.example.withoutGcm"
        }
    }
    

    And outside the configuration, inside the build.gradle file:

    android.productFlavors.each { flavor ->
        if (getGradle().getStartParameter().getTaskRequests().toString().toLowerCase().contains(flavor.name) && flavor.ext.useGoogleGcm) {
            println("Building flavor with Google GCM [${flavor.name}] - applying plugin")
            apply plugin: 'com.google.gms.google-services'
        }
    }
    

提交回复
热议问题