I´m really desperate about this problem. I´m trying to solve this issue for such a long time now, but I just can´t get it working.
My goal is to use Firebase withhin my Nativescript-App, which also uses Angular 7, but every time I try to "begin" using firebase, I get the following error:
Default FirebaseApp is not initialized in this process com.nativescript. Make sure to call FirebaseApp.initializeApp(Context) first.
I already tried that. I followed this tutorial:https://github.com/EddyVerbruggen/nativescript-plugin-firebase
My Nativescript App is build in "Typescript", so I choose the Typescript-way.
Since I don´t have the app.js, I started the .init in app.ts like so:
import * as application from "tns-core-modules/application";
import * as FirebaseApp from "nativescript-plugin-firebase/app"
import { environment } from './environments/environment';
FirebaseApp.initializeApp(environment.firebase);
import * as firebase from "nativescript-plugin-firebase";
firebase.init({
// Optionally pass in properties for database, authentication and cloud messaging,
// see their respective docs.
}).then(
() => {
console.log("firebase.init done");
},
error => {
console.log(`firebase.init error: ${error}`);
}
);
application.run({ moduleName: "app-root" });
When I try FirebaseApp.initializeApp(environment.firebase), it crashes and says in the log:
S: firebase.init error: Firebase already initialized
Successfully synced application com.nativescript. on device 97412f42.
System.err: An uncaught Exception occurred on "main" thread.
System.err: Unable to start activity ComponentInfo{com.nativescript./com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
System.err: Error: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.nativescript.. Make sure to call FirebaseApp.initializeApp(Context) first.
System.err:
...
That´s interesting, because above it says "already initialized", but right after that it says "FirebaseApp is not initialized". Okay, so I decide to remove firebase.init({...}) because maybe that´s just too much init, but obviously nope:
System.err: Unable to start activity ComponentInfo{com.nativescript./com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
System.err: Error: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.nativescript. Make sure to call FirebaseApp.initializeApp(Context) first.
System.err:
...
Don´t worry, I purposly removed com.native.script.THEID, just in case.
When I decide to replace FirebaseApp.initializeApp(environment.firebase) with the firebase.init-part it also gives the same error.
My environment.ts is in a folder called environment and it´s in the same directory as app.ts (the folder).
This is how environment.ts is looking like:
export const environment = {
production: true,
firebase: {
apiKey: 'THE API KEY',
authDomain: 'THE AUTH DOMAIN',
databaseURL: 'THE DATABASE URL',
projectId: 'THE PROJECT ID',
storageBucket: 'THE STORAGE BUCKET',
messagingSenderId: 'THE SENDER ID'
},
};
I already download the google-services.json from Firebase Console (where you setup your App) and pasted it into app/App_Resources/Android/
Please guys, I really don´t know any further. I even tried the second page of Google Search.
If you need any infos, please let me know.
MY SOLUTION
Unfortunately I had to abandon this project and create a new one with angular-templates.
I must have messed something up while enabling mutliDex since I had struggles enabling it back then.
My theory is that, by messing up the activation of multiDex, I probably create two instances of my app build when I run tns run android.
So, the only solution was to start over again, but at least the Firebase initialization works now just fine!
Related
Am currently trying to setup notifications on my managed expo project
Expo version 47.0.0
Expo notifications version 0.17.0
Device: Samsung Galaxy s10
Android version 12
I am currently just trying to get the basic setup itself working and retrieve my devices push token. This should be done using Notifications.getExpoPushTokenAsync() as described here.
The Problem
My error is strange, when I call getExpoPushTokenAsync it does indeed get me the expo push token, however shortly after my app crashes with the following messages
ERROR TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[1], "../../../src/util").types.isPromise')
WARN [expo-notifications] Error encountered while updating server registration with latest device push token. [TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[5], "#ide/backoff").computeNextBackoffInterval')]
I have tried
re-installing node_modules and expo-notifications but still get the same.
I can definitely see the #ide/backoff package is installed in my node_modules.
I also followed these instructions to setup firebase in app, even though my understanding is that it should work out of the box in expo go app while devving.
One other interesting thing is that I can call Notifications.getDevicePushTokenAsync() fine with no error. But still get the same error if i pass that in to getExpoPushTokenAsync method after. At a surface level it seems like somehow the request out to expo services to get the expo push token is both passing and failing 🤷♂️
const devicePushTokenResponse = await Notifications.getDevicePushTokenAsync();
const expoPushTokenResponse = await Notifications.getExpoPushTokenAsync({
devicePushToken: devicePushTokenResponse,
}); // <--- Returns token & errors a few seconds later
Couldn't see any other posts with this error and expo-notifications, so would be keen to see if anyone else has ran into / fixed a similar issue recently
Cheers
Alright I figured it out, it was somewhat hinted at by this line
ERROR TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[1], "../../../src/util").types.isPromise')
And more specifically the fact that a node_modules dependency is referencing 3 levels up in the file system.
The solution
Turns out that for some reason my module resolver (defined in babel.config.js) was resolving my project's util folder instead of the packages util folder. I think this was compounded by my metro config making use of the inlineRequires functionality to improve performance (see more)
I am sure there is some actual config that could be updated to exclude node_modules from using inline requires (i did try use a blocklist to no avail), but as an interim, i was able to get it working fine by changing the path of my util folder to be #my-project/util so that it avoids future collisions.
Hope this helps anyone who runs into the same issue in the future :)
I implemented Firebase into a Unity app I am creating. There are two buttons that will run the two functions to create a new user and login an existing user. So far this functionality works on my PC, however whenever I try to deploy it to my android phone or Mac I end up getting the following error in the console.
DllNotFoundException: FirebaseCppApp-5.1.0
Firebase.AppUtilPINVOKE+SWIGExceptionHelper..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for SWIGExceptionHelper
Firebase.AppUtilPINVOKE..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Firebase.AppUtilPINVOKE
Firebase.AppUtil.SetLogFunction (Firebase.LogMessageDelegate arg0)
It appears there is a missing .dll file, however I cannot for the life of me find out how to include it within the project file. I also have double checked the package name and it is the exact same name as the one made for my Firebase project, the google-services JSON in the root of the project, and the Api compatibility level is set to .NET 2.0. On top of that I also uninstalled and reinstalled the app a few times. I also tried using the Play Services Resolver which didn't help much at all either.
Similar error here, only with Firebase Cloud Messaging. After tinkering around in a fashion similar to yours I concluded that it was caused by corruption during import of Firebase Package.
What worked for me:
Deleted each and every folder created while importing Firebase Package.
Reimported Firebase Package
I'm trying to run a test with Robolectric and it has an integration with Firebase. I have a project MyProject - Test that I'll be using to run the tests in a real instance of the database.
The problem is that, when running cleanup before test, I have the error:
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process null. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.cgbros.silkhub.activity.listener.LoginActivityUnitTest.cleanUp(LoginActivityUnitTest.kt:26) <28 internal calls>
The test file:
https://gist.github.com/augustoerico/e88d3e5b59ae5d023d83c114b8ffa708
(I tried to copy-paste the source here. Failed miserably...)
Any insights on how I can make this work?
Thank you!
Ok, I've figured it out. It's actually a conceptual problem. The problem is that I'm trying to use the Firebase Android SDK to run a test outside of the Android context. I mean, my test is not an Android application, and I'm trying to use the Android SDK. All FirebaseApp.initializeApp() need a Context as a parameter.
So, what I have to do is to find a way to interact with my FirebaseDatabase. I think I can go with firebase-admin, or maybe use this one: https://github.com/bane73/firebase4j
Thank you for taking the time to help me (:
** Update **
I've opted to go with the Firebase REST API https://firebase.google.com/docs/reference/rest/database/
For future reference, I'm giving public full access, by tweaking the rules, so it is easier to write the tests setup and cleanup.
I've had the same problem and fixed it by initializing Firebase in the before step of my unit test:
FirebaseApp.initializeApp(InstrumentationRegistry.getInstrumentation().targetContext)
I also had the same issue a few day ago and i solve it in the same way the error says. You get that error because you're trying to get an instance of Firebase without initialize it. Please add this line of code before you try to get an instance of Firebase like this:
FirebaseApp.initializeApp(this);
Also, as Franks says, please be sure you have the following line of code added in your build.gradle file, as the last line of your entire file.
apply plugin: 'com.google.gms.google-services'
I used the most simple and straightforward approach.
Since you init your Firebase App in your Application, just create a variable there. For example,
//Your Application.class
open var isTestMode = false
onCreate(){
if(!isTestMode){
//Init your Firebase app
}
}
And then in Robolectric Application just extend your application and override the variable. In this case don't forget to provide configuration
#Config(application = TestApplication::class)
I also faced the above issue. Do all plugin download and checks by nuget. But in the end, I found the crashing was due to , Application Package Name not matching the one Assigned in Google Dev.
Application package name must matche the one that assigned in the Google Dev. Console
after add this line and then you get error
FirebaseApp.initializeApp(this);
then you have to do that also
add this line to Gradle (App)
apply plugin: 'com.google.gms.google-services'
add this line to Gradle (Project)
classpath 'com.google.gms:google-services:3.2.1'
also check if no dependncy is missing and make sure you add google-services.json
Java.Lang.IllegalStateException: Default FirebaseApp is not initialized in this process TestChartApp.TestChartApp. Make sure to call FirebaseApp.initializeApp(Context) first.
this is my code i am using
FirebaseApp.InitializeApp(this);
try
{
throw new NotImplementedException();
}
catch (System.Exception ex)
{
FirebaseCrash.Report(ex);
}
I am new to implement firebase crash reporting i am trying to implement crash report but it is throwing an error. please help me how can i solve that.
Review your logcat output for FirebaseInitProvider tags, if you are getting:
[FirebaseInitProvider] FirebaseApp initialization unsuccessful
Then the two major things to check:
Make sure that your google-services.json is assigned a build action of GoogleServicesJson
Check that your application package name matches the one that you assigned in the Google Dev. Console
A successful FirebaseApp registration will result in the following logcat:
FirebaseInitProvider: FirebaseApp initialization successful
After assigned the build action as GoogleServicesJson its working.
Try entering the following in MainActivity.cs after the LoadApplication call.
FirebaseApp app = FirebaseApp.InitializeApp(Android.App.Application.Context);
The resolution for me was toggling the BuildAction for the google-services.json to GoogleServicesJson.
Even though the google-services.json properties showed BuildAction set to GoogleServicesJson, I was still having the error "Default FirebaseApp is not initialized in this process Make sure to call FirebaseApp.initializeApp(Context) first".
I was able to resolve this issue by setting BuildAction to "None" then setting it back to "GoogleServicesJson". When I got latest version from source control the BuildAction must not have carried over to my local copy (although it showed as such).
I was able to run my Angular-Meteor Cordova application no problem until I made a minor change. Now whenever I run meteor run android-device it tries to start the application on the device but when it starts has trouble loading the packages. This is the log out put:
=> App running at: http://localhost:3000/
=> Started app on Android Device.
I20160308-12:51:21.879(0) (android:http://meteor.local/packages/angular_angular.js:1) Uncaught SyntaxError: Unexpected token <
I20160308-12:51:21.954(0) (android:http://meteor.local/packages/angular_angular-animate.js:32) Uncaught TypeError: Cannot read property 'noop' of undefined
I20160308-12:51:21.955(0) (android:http://meteor.local/packages/angular_angular-sanitize.js:42) Uncaught TypeError: Cannot read property '$$minErr' of undefined
I20160308-12:51:21.955(0) (android:http://meteor.local/packages/angularui_angular-ui-router.js:49) Uncaught TypeError: Cannot read property 'isDefined' of undefined
I20160308-12:51:22.359(0) (android:http://meteor.local/packages/driftyco_ionic.js:13355) Uncaught ReferenceError: angular is not defined
...
Oh, I should say this runs on the desktop fine.
----- Update -----
I've inspected the WebView with Chrome and weirdly enough the offending file angular_angular.js seems to contain HTML! See picture below:
This is totally different from the contents of the same file on the desktop, which contains valid javascript.
After inspecting the webview via Chrome I discovered the mobile was using old application files. Answer was to go into the settings -> apps -> myapp and clear the cache/local files.
I thought this would have been expired by meteor but it's not the case. Or perhaps it didn't do it one time because of an error. I'll find out soon enough, but if not I'll have to figure out a way to stop the caching of obsolete files.