如何在 Nativescript 中使用 SDK Firebase (Android)
How to use the SDK Firebase (Android) in Nativescript
我正在尝试在 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
同时,非常感谢您的回复@attdona :)
我通过或多或少做了你所做的来解决了。
唯一的区别是:
- 为了使用动态 build.gralde 我创建了一个 hook 来替换
原始的与我一起编译。
- 总是使用 hook 我复制了
文件 google-services.json 从 App_Resources/Android/ 到
platforms/android/app
我正在尝试在 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
同时,非常感谢您的回复@attdona :)
我通过或多或少做了你所做的来解决了。
唯一的区别是:
- 为了使用动态 build.gralde 我创建了一个 hook 来替换 原始的与我一起编译。
- 总是使用 hook 我复制了 文件 google-services.json 从 App_Resources/Android/ 到 platforms/android/app