添加 firebase 插件后,Nativescript 应用程序在 android 上不断崩溃

Nativescript app keeps crashing on android after adding firebase plugin

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

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

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

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

在我的例子中,我的应用程序 (nativescript vue) 在成功复制 google-services.json 后崩溃,但在呈现应用程序时。我通过在 App-level 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 link 中列出的 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    
    ...    
  }    
}

我希望这对面临类似问题的任何人有所帮助。