在做的安卓应用需要在 debug 和 release build中使用不同的谷歌服务账号,要用到不同的google-serivces.json ,手动替换的话太费时费力,好在万能的gradle可以完成轻松解决这个问题。解决步骤如下:

假设两个json文件分别放在一下目录:

app/src/debug/google_services.json
app/src/main/google_services.json

在build.gradle新加两个task

task switchToDebug(type: Copy) {
    description = 'Switches to DEBUG google-services.json'
    from "src/debug"
    include "google-services.json"
    into "."
}

task switchToRelease(type: Copy) {
    description = 'Switches to RELEASE google-services.json'
    from "src/release"
    include "google-services.json"
    into "."
}

 

接下来需要根据不同的build分别执行这两个task,‘com.google.gms.google-services’这个plugin定义两个task分别是

processDebugGoogleServices
processReleaseGoogleServices

我们直接借用他们,添加:

afterEvaluate {
    processDebugGoogleServices.dependsOn switchToDebug
    processReleaseGoogleServices.dependsOn switchToRelease
}

这样就会在编不同build时使用对应的google-services.json了。

 

 

原文: https://medium.com/google-cloud/automatic-per-variant-google-services-json-configurations-with-gradle-d3d3e40abc0e#.pxurhrjle

http://www.limelife.cn/p/17/

相关文章:

  • 2021-04-14
  • 2021-09-24
  • 2021-11-13
  • 2022-02-10
  • 2021-07-01
  • 2021-08-26
  • 2021-11-27
  • 2021-11-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-09-10
  • 2021-05-21
  • 2022-12-23
  • 2022-02-22
相关资源
相似解决方案