Google 在播放服务插件 2.0 版中包含了对口味的支持。自从这个版本gradle plugin com.google.gms:google-services:2.0.0-alpha3
你可以这样做
第1步:添加到gradle
// To auto-generate google map api key of google-services.json
implementation 'com.google.android.gms:play-services-maps:17.0.0'
步骤2:添加到AndroidManifest.xml中的application标签中
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_api_key" />
第 3 步:从 firebase 下载每个风味 JSON 文件并添加它
app/src/
flavor1/google-services.json
flavor2/google-services.json
该插件的 3.0.0 版本会在这些位置搜索 JSON 文件(考虑到您有一个flavor
flavor1 和构建类型debug
):
/app/src/debug/google-services.json
/app/src/debug/flavor1/google-services.json
/app/google-services.json
即使使用flavorDimensions,这对我也有用。我在一个维度上有免费和付费,在另一个维度上有模拟和产品。我还有 3 种构建类型:调试、发布和暂存。这就是我的 FreeProd 风格项目中的样子:
多少个 google-services.json 文件取决于您的项目特征,但每个 Google 项目至少需要一个 JSON 文件。
如果您想了解有关此插件如何处理这些 JSON 文件的更多详细信息,请参阅以下内容:https://github.com/googlesamples/google-services/issues/54#issuecomment-165824720
官方文档链接:https://developers.google.com/android/guides/google-services-plugin
包含更新信息的博客文章:https://firebase.googleblog.com/2016/08/organizing-your-firebase-enabled-android-app-builds.html
并到这里查看该插件的最新版本:https://mvnrepository.com/artifact/com.google.gms/google-services?repo=google