Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

How to configure Firebase in Nativescript (Angular)

1. Install Firebase Core

npm install @nativescript/firebase-core
Enter fullscreen modeExit fullscreen mode

2. Set Up a 🔥 Firebase Project

  • In the Firebase Console, create a new project.
  • SelectAndroid and/oriOS as your target platform(s).

3. Configure Your App ☎️

  • Follow the Firebase setup wizard to specify your app name and properties. This process will generate a google-services.json file for Android.

4. Add Configuration File

App_Resources/Android/src/google-services.json
Enter fullscreen modeExit fullscreen mode

Note: Ensure the file is placed inside the src directory.

5. Initialize Firebase in Your App

  • In your \src\main.ts, add the following code:
import{firebase}from'@nativescript/firebase-core';// ...rest of your codeawaitfirebase().initializeApp();// ...rest of your code
Enter fullscreen modeExit fullscreen mode

6. Clean and Run the Project

ns cleanns run android
Enter fullscreen modeExit fullscreen mode

7. Troubleshooting: Initialization Error ⚠️

  • If you encounter the following error:
Firebaseinitializationerror:Error:Cannotreadpropertiesofundefined(reading'FirebaseApp')
Enter fullscreen modeExit fullscreen mode

This usually indicates a problem with the Firebase configuration, often due to missing fingerprint authentication (SHA-1).


How to Add SHA-1 Fingerprint

  1. In the Firebase Console, go to your project settings and locate the section to download thegoogle-services.json file and add a fingerprint.
  2. Generate your SHA-1 fingerprint by running the following command inside theplatforms/android directory:
 ./gradlew signingReport
Enter fullscreen modeExit fullscreen mode
  1. The output will include a section similar to:
Variant: debugConfig: debugStore: /.../.android/debug.keystoreAlias: AndroidDebugKeySHA1: XX:XX:XX:XXXX:XXXX:XX:...SHA-256: ...
Enter fullscreen modeExit fullscreen mode
  1. Copy theSHA1 value and add it to your Firebase project.
  2. Download the updatedgoogle-services.json and repeat step 4 above (replace the file inApp_Resources/Android/src/).
  3. Runns clean andns run android again.

8. Verifying the Integration

  • You can verify initialization by logging the result offirebase().initializeApp() inmain.ts, or by integrating Firebase Analytics to see events in realtime:
import'@nativescript/firebase-analytics';awaitfirebase().initializeApp();firebase().analytics().setAnalyticsCollectionEnabled(true);firebase().analytics().logEvent('app_start',{});
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Eternal Thinker
  • Location
    Argentina
  • Education
    UTN
  • Pronouns
    He
  • Work
    Software Developer
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp