gpt4 book ai didi

android - 如何在 Nativescript 中使用 SDK Firebase (Android)

转载 作者:行者123 更新时间:2023-11-29 02:32:17 24 4
gpt4 key购买 nike

我正在尝试在 Android 上原生使用 sdk Firebase,但是当我尝试使用以下方法初始化 Firebase 时:

com.google.firebase.FirebaseApp.initializeApp(utils.ad.getApplicationContext();

我收到这个错误

System.err: Error: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process *******. Make sure to call FirebaseApp.initializeApp(Context) first.

在我的 app.gradle 中:

dependencies {
compile 'com.google.firebase:firebase-core:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile "com.google.android.gms:play-services-base:11.8.0"
}

可以帮我吗?

最佳答案

将规则添加到 platforms/android/build.gradle 文件,以包含 google-services 插件和 Google 的 Maven 存储库:

buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.1.1' // google-services plugin
}
}

allprojects {
repositories {
// ...
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}

将 firebase 依赖项插入 App_Resources/Android/app.gradle:

dependencies {
compile 'com.google.firebase:firebase-core:11.8.0'
//compile 'com.google.firebase:firebase-messaging:11.8.0'
//compile "com.google.android.gms:play-services-base:11.8.0"
// ...
}

并在 App_Resources/Android/app.gradle 的末尾插入:

apply plugin: 'com.google.gms.google-services'

最后,如果你遇到错误:

> File google-services.json is missing. The Google Services Plugin cannot function without it.

手动复制 google-services.json 文件:

cp app/App_Resources/Android/google-services.json platforms/android/app/google-services.json

关于android - 如何在 Nativescript 中使用 SDK Firebase (Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48949808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com