Ionic firebase 指定 google-services.json [英] Ionic firebase specify google-services.json

查看:25
本文介绍了Ionic firebase 指定 google-services.json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ionic 3 项目,我想将 firebase 添加到项目中.

I have an ionic 3 project and I wanted to add firebase to the project.

我安装了 firebase cordova 插件并将我的 google-services.json 放在 resources/android 中,但在解析 google-services.json 时出现错误:找不到与包匹配的客户端名字[这里的名字]

I installed the firebase cordova plugin and placed my google-services.json in resources/android but I get an error while parsing google-services.json : No matching client found for package name [name here]

当我查看放入 resources/android 的 google-services.json 时,包名称是正确的,但是当我查看 platforms/android 时,文件是完全不同,包名是 com.github.cordova_plugin_firebase

When I look at my google-services.json that I put in resources/android the package name is correct but when I look in platforms/android the file is completely different and the package name is com.github.cordova_plugin_firebase

有人知道如何确保使用正确的 google-services.json 吗?

Anyone know how can make sure the correct google-services.json is used?

推荐答案

试试这个步骤.

  1. 首先使用 ionic cordova platform remove android

将 google-services.json 文件复制到根目录(package.json/config.xml 文件所在的位置).

copy google-services.json file to the root directory (where package.json/config.xml file).

然后尝试使用 ionic cordova platform add android 添加 android 平台.然后检查自动复制的 android 文件夹 google-services.json 文件,如果没有,则将其复制到 android 文件夹.

then try to add android platoform using ionic cordova platform add android.then check your android folder google-services.json file copied automatically,if not then copy it to the android folder.

然后检查您的 build.gradle 文件以包含 google-services插件和 Google 的 Maven 存储库:

Then check your build.gradle fileto include the google-services plugin and the Google's Maven repository:

buildscript{
   //add dependencies as per your google-service version
 dependencies {
     classpath 'com.google.gms:google-services:4.2.0' // google-services plugin 
 }

 allprojects {
   repositories {
       google() // Google's Maven repository
 }
}

  • 然后,在您的模块 Gradle 文件 (app/build.gradle) 中,在文件底部添加 apply plugin 行以启用 Gradle 插件

  • Then, in your module Gradle file (app/build.gradle), add the apply plugin line at the bottom of the file to enable the Gradle plugin

    dependencies {
        implementation 'com.google.firebase:firebase-core:16.0.7'
     }
    
    // ADD THIS AT THE BOTTOM
    apply plugin: 'com.google.gms.google-services'
    

  • 注意:如果您使用 codova-android >= 7,您现在必须添加

     <platform name="android">
         <resource-file src="google-services.json" target="app/google-services.json" />
     </platform>
    

    这篇关于Ionic firebase 指定 google-services.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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