Android Studio:如何在产品风格中排除Google服务模块? [英] Android Studio: How to exclude google-services module in product flavor?

查看:305
本文介绍了Android Studio:如何在产品风格中排除Google服务模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android项目中,有几种产品风格:

  buildTypes {
release {}
debug {}
staging {}
}

productFlavors {
freeVersion {}
proVersion {}
partnerVersion {}
}

另外,我使用Google Analytics:

  apply plugin:'com.google.gms.google-services'

依赖关系{
compile'c​​om.google.android.gms: play-services-analytics:8.4.0'
}

如何排除google-services在其中之一?例如,在:

  freeVersion {} 


解决方案

请注意使用 freeCompile 并声明一个变量 flavor 来有条件地应用插件。

  apply plugin:'com.android.application'

def flavor

android {

....

....

productFlavors {
free {
applicationId com.anandbibek.builditbigger.free
flavor =free
}
支付{
applicationIdcom.anandbibek.builditbigger.paid
flavor =paid
}
}
}

依赖关系{

//为AdMob添加
freeCompile'c​​om.google.firebase :firebase-ads:9.6.1'

compile'c​​om.android.support:appcompat-v7:24.2.1'
compile'c​​om.google.code.findbugs:jsr305:2.0 .1'

}
if(flavor ==free){
apply plugin:'com.google.gms.google-services'
}

请确保将 google-services.json 文件在味道特定的文件夹中。就我而言,我只把它放在 app / src / free 中。当您在主项目gradle文件中使用 classpath'com.google.gms:google-services:3.0.0'时,此工具可用。


In my Android project, there are several product flavors:

buildTypes {
    release {}
    debug {}
    staging {}
}

productFlavors {
    freeVersion {}
    proVersion {}
    partnerVersion {}
}

Also, i use Google Analytics:

apply plugin: 'com.google.gms.google-services'

dependencies {
    compile 'com.google.android.gms:play-services-analytics:8.4.0'
}

How to exclude google-services in one of them? For example, in:

freeVersion {}

解决方案

Please notice the use of freeCompile and declaring a variable flavor to conditionally apply the plugin.

apply plugin: 'com.android.application'

def flavor

android {

    ....

    ....

    productFlavors {
        free {
            applicationId "com.anandbibek.builditbigger.free"
            flavor = "free"
        }
        paid {
            applicationId "com.anandbibek.builditbigger.paid"
            flavor = "paid"
        }
    }
}

dependencies {

    // Added for AdMob
    freeCompile 'com.google.firebase:firebase-ads:9.6.1'

    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.google.code.findbugs:jsr305:2.0.1'

}
if(flavor == "free") {
    apply plugin: 'com.google.gms.google-services'
}

Make sure you put the google-services.json file in flavor specific folder. In my case, I put that in app/src/free only . This facility is available when you use classpath 'com.google.gms:google-services:3.0.0' in your main project gradle file.

这篇关于Android Studio:如何在产品风格中排除Google服务模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆