How do i keep different configurations for my android app with GCM 3.0

感情迁移 提交于 2019-12-18 11:55:41

问题


I want to keep different configurations for my debug/release build variants but apparently, the google-services.json file only allows for one. Is there any alternative? Is there a way to keep several files?


回答1:


I'm using this workaround to solve a similar issue with build flavours.

The flavour specific google-service.json files are stored under /app/src/{flavour-name}/google-service.json. To copy this to the /app dir the following code may be added to the /app/build.gradle file:

    gradle.taskGraph.beforeTask { Task task ->
        if(task.name ==~ /process.*GoogleServices/) {
            android.applicationVariants.all { variant ->
                if(task.name ==~ /(?i)process${variant.name}GoogleServices/){ 
                    copy {
                        from "/src/${variant.flavorName}"
                        into '.'
                        include 'google-services.json'
                    }
                }
            }
        }
    }

In the absence of flavours (as I understand your question) the following /app/build.gradle code snippet did the job in an android studio test project:

    gradle.taskGraph.beforeTask { Task task ->
        if(task.name ==~ /process.*GoogleServices/) {
            android.applicationVariants.all { variant ->
                if(task.name ==~ /(?i)process${variant.name}GoogleServices/){
                    copy {
                        from '.'
                        into '.'
                        rename { String fileName ->
                            fileName.replace("google-services-${variant.name}.json", 'google-services.json')
                        }
                        include "google-services-${variant.name}.json"
                    }
                }
            }
        }
    }

The snippet expects a google-services-debug.json and a google-services-release.json in your /app dir and copies and renames it to google-services.json.

Hope this helps.




回答2:


No there is no way to define build specific configs at this point. Good idea though, seems like something useful.



来源:https://stackoverflow.com/questions/30901610/how-do-i-keep-different-configurations-for-my-android-app-with-gcm-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!