【问题标题】:Nativescript app keeps crashing on android after adding firebase plugin添加firebase插件后,Nativescript应用程序在android上不断崩溃
【发布时间】:2020-05-17 20:39:36
【问题描述】:

在我添加 firebase 插件之前,我的 nativescript 应用程序运行良好。现在,当我在我的设备上运行它时,它会给出错误消息 'app has stop working' 。请帮忙

这是我正在使用的插件 https://github.com/EddyVerbruggen/nativescript-plugin-firebase

【问题讨论】:

  • 你添加了 google-services.json 文件吗?
  • 是的,我有。但要明确一点,它必须与我的 AndroidManifest.xml 位于同一文件夹中。因为文档说我应该把它放在这里C:\Users\user\tabs\app\App_Resources\Android\google-services.json 但我的 androidmanifest 在这里`C:\Users\user\tabs\app\App_Resources\Android\src`
  • 您使用 Firebase 的哪些服务?您是否确保在firebase.nativescript.json 中启用了您使用的所有服务?您是否尝试过干净的构建?您是否编写了在启动/初始化方法时访问插件 API 的任何代码?
  • 是的,在其文档中,它说我应该将 fiebase.init 添加到我的 app.js 中,我做到了。我也会尝试你的其他解决方案@Manoj

标签: android firebase nativescript nativescript-firebase


【解决方案1】:

在 Windows 系统上为 android 构建时,我发现问题出在插件上。在 macbook 上构建时不会发生这种情况。我已经在他们的 github 存储库上记录了一个投诉,其他一些人和我有同样的问题。里面有一些答案,你可以去看看

【讨论】:

    【解决方案2】:

    google-services.json 应该在 app/App_Resources/Android 你在使用 tns run 之类的吗?如果是这样,终端的整个错误是什么?应用停止工作听起来不像是完整的输出。

    【讨论】:

      【解决方案3】:

      在我的情况下,我的应用程序(nativescript vue)在成功复制 google-services.json 后崩溃,但在呈现应用程序时崩溃。我通过在 App 级 build.gradle (//build.gradle) 文件中添加所有必需的依赖项来解决它,如下所示:

      apply plugin: 'com.android.application'
      
      // Add this line
      
      apply plugin: 'com.google.gms.google-services'
      
      dependencies {    
        // add the Firebase SDK for Google Analytics
      
        implementation 'com.google.firebase:firebase-analytics:17.2.2'
      
        // add SDKs for any other desired Firebase products
        // https://firebase.google.com/docs/android/setup#available-libraries 
      

      确保根据您已启用的 Firebase 功能添加所有必需的依赖项,方法是参考上面 SDK 链接中列出的 Gradle 依赖项。请记住,Analytics 还需要包含其他几个依赖项。添加所有必需的依赖项后,我的应用程序启动时没有崩溃。

      还要确保在项目级 build.gradle (/build.gradle) 文件中:

      buildscript {      
      repositories {    
          // Check that you have the following line (if not, add it):
      
          google()  // Google's Maven repository
      
        }    
        dependencies {    
          ...    
          // Add this line    
          classpath 'com.google.gms:google-services:4.3.3'    
        }    
      }   
      
      allprojects {    
        ...    
        repositories {    
          // Check that you have the following line (if not, add it):    
          google()  // Google's Maven repository    
          ...    
        }    
      }
      

      我希望这可以帮助任何面临类似问题的人。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-10-29
        • 1970-01-01
        • 1970-01-01
        • 2021-02-11
        • 1970-01-01
        • 2019-09-25
        • 1970-01-01
        • 2013-03-26
        相关资源
        最近更新 更多