baumblatt / capacitor-firebase-auth

Capacitor Firebase Authentication Plugin
MIT License
261 stars 129 forks source link

Android application does not launch #19

Open minaph opened 5 years ago

minaph commented 5 years ago

I made an application with google sign-in but it doesn't launch. Its build worked without any error. When I run the APK, Application will shut down immediately. I couldn't get any error code(I tried USB debug and emulator).

  1. APK was signed with SHA-1.
  2. Google sign-in is valid.

I'm using an Android device. I could see the app work only in localhost (npm run serve) and got this error.

[Vue warn]: Error in v-on handler: "Error: Either an instance of firebase.auth.Auth must be passed as an argument to the firebase.auth.PhoneAuthProvider constructor, or the default firebase App instance must be initialized via firebase.initializeApp()."

found in

---> at src/components/Auth4.vue

at src/App.vue Any advice?
baumblatt commented 5 years ago

Hi Yuki,

There is a good discussion about firebase App not initialized at issue #1 .

Did you got any exception in logcat?

Best Regards,
Bernardo Baumblatt

baumblatt commented 5 years ago

Hi Yuki,

Did you solve your issue? If not, can you shared the your logcat?

Best regards,
Bernardo Baumblatt.

piotrzuzak commented 4 years ago

Hi @baumblatt,

My context:

  1. Application does not crash after adding plugin (I am not sure if plugin is loaded correctly Futuny starting)
  2. Application has google-services.json exported from firbase console to level of "android/app"
  3. Application's google-services.json has SHA-1 and configured Firebase Android Application according to instructions

Issur:

  1. I am getting the same exception on logcat console as @minaph:

Error: Either an instance of firebase.auth.Auth must be passed as an argument to the firebase.auth.PhoneAuthProvider constructor, or the default firebase App instance must be initialized via firebase.initializeApp()

Below all logs (logcat) under "firebase" key from search input:

2019-10-14 22:08:42.152 8850-8870/com.fasttrack.app W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found. 2019-10-14 22:08:42.187 8850-8850/com.fasttrack.app D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization. 2019-10-14 22:08:42.188 8850-8850/com.fasttrack.app D/FirebaseApp: com.google.android.gms.measurement.AppMeasurement is not linked. Skipping initialization. 2019-10-14 22:08:42.188 8850-8850/com.fasttrack.app I/FirebaseInitProvider: FirebaseApp initialization successful 2019-10-14 22:08:42.209 8850-8873/com.fasttrack.app W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found. 2019-10-14 22:08:42.241 8850-8873/com.fasttrack.app I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions. 2019-10-14 22:08:42.242 8850-8873/com.fasttrack.app I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation 2019-10-14 22:08:43.874 8850-8850/com.fasttrack.app D/Capacitor: Registering plugin: CapacitorFirebaseAuth 2019-10-14 22:08:43.883 8850-8850/com.fasttrack.app D/CapacitorFirebaseAuth: Verifying if the default FirebaseApp was initialized. 2019-10-14 22:08:43.885 8850-8850/com.fasttrack.app D/CapacitorFirebaseAuth: Retrieving FirebaseAuth instance 2019-10-14 22:08:43.885 8850-8850/com.fasttrack.app D/CapacitorFirebaseAuth: Initializing Google Provider 2019-10-14 22:08:43.921 8850-8850/com.fasttrack.app D/CapacitorFirebaseAuth: Google Provider Initialized

Please help!

baumblatt commented 4 years ago

Hi Piotrzuzak,

This happens when your Firebase application is not initialized correctly, but in your case this is very strange, because according to the logs sent the plugin has been successfully initialized.

2019-10-14 22:08:43.874 8850-8850/com.fasttrack.app D/Capacitor: Registering plugin: CapacitorFirebaseAuth 2019-10-14 22:08:43.883 8850-8850/com.fasttrack.app D/CapacitorFirebaseAuth: Verifying if the default FirebaseApp was initialized. 2019-10-14 22:08:43.885 8850-8850/com.fasttrack.app D/CapacitorFirebaseAuth: Retrieving FirebaseAuth instance 2019-10-14 22:08:43.885 8850-8850/com.fasttrack.app D/CapacitorFirebaseAuth: Initializing Google Provider 2019-10-14 22:08:43.921 8850-8850/com.fasttrack.app D/CapacitorFirebaseAuth: Google Provider Initialized

Please, can you share a log during the authentication process?

Meanwhile, I can't see the Phone provider initialization on the log, can you share your capacitor.config.json? Or you can check by your self that your providers list has phone as shown on docs here: https://github.com/baumblatt/capacitor-firebase-auth/blob/master/README.MD#capacitor-plugins

Best regards, Bernardo Baumblatt

On Mon, Oct 14, 2019, 17:21 piotrzuzak notifications@github.com wrote:

Hi @baumblatt https://github.com/baumblatt,

My context:

  1. Application does not crash after adding plugin (I am not sure if plugin is loaded correctly under starting)
  2. Application has google-services.json exported from firbase console to level of "android/app"
  3. Application's google-services.json has with SHA-1 and configured Firebase Android Application according to instructions

Two issues here:

  1. Documentation for the plugin does not inform us what to paste google-services.json (is it "android/app" directory level? - I am guessing yes if exception warning does not show in console
  2. I am getting the same exception from logcat as @minaph https://github.com/minaph:

Error: Either an instance of firebase.auth.Auth must be passed as an argument to the firebase.auth.PhoneAuthProvider constructor, or the default firebase App instance must be initialized via firebase.initializeApp()

Below all logs under "firebase" key in search:

2019-10-14 22:08:42.152 8850-8870/com.fasttrack.app W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found. 2019-10-14 22:08:42.187 8850-8850/com.fasttrack.app D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization. 2019-10-14 22:08:42.188 8850-8850/com.fasttrack.app D/FirebaseApp: com.google.android.gms.measurement.AppMeasurement is not linked. Skipping initialization. 2019-10-14 22:08:42.188 8850-8850/com.fasttrack.app I/FirebaseInitProvider: FirebaseApp initialization successful 2019-10-14 22:08:42.209 8850-8873/com.fasttrack.app W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found. 2019-10-14 22:08:42.241 8850-8873/com.fasttrack.app I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions. 2019-10-14 22:08:42.242 8850-8873/com.fasttrack.app I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation 2019-10-14 22:08:43.874 8850-8850/com.fasttrack.app D/Capacitor: Registering plugin: CapacitorFirebaseAuth 2019-10-14 22:08:43.883 8850-8850/com.fasttrack.app D/CapacitorFirebaseAuth: Verifying if the default FirebaseApp was initialized. 2019-10-14 22:08:43.885 8850-8850/com.fasttrack.app D/CapacitorFirebaseAuth: Retrieving FirebaseAuth instance 2019-10-14 22:08:43.885 8850-8850/com.fasttrack.app D/CapacitorFirebaseAuth: Initializing Google Provider 2019-10-14 22:08:43.921 8850-8850/com.fasttrack.app D/CapacitorFirebaseAuth: Google Provider Initialized

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/baumblatt/capacitor-firebase-auth/issues/19?email_source=notifications&email_token=ADJMCV3I24LPT5NV3OCUH3TQOTIFVA5CNFSM4IV6XOI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBGLVPI#issuecomment-541899453, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADJMCVZW4OFC4I6LQKU5IYDQOTIFVANCNFSM4IV6XOIQ .

piotrzuzak commented 4 years ago

Hi @baumblatt,

Thank you for your respond. Let's clarify some things:

  1. I need only google and facebook option - these ones are configured through firebase
  2. I don't need phone provider as authentication should be based on firebase authentication only, without any phone step verification
  3. Here is capacitor config:

{ "appId": "com.fasttrack.app", "appName": "FasttrackApp", "bundledWebRuntime": false, "npmClient": "npm", "webDir": "www", "plugins": { "SplashScreen": { "launchAutoHide": false }, "CapacitorFirebaseAuth": { "providers": ["google.com"], "languageCode": "en", "nativeAuth": false, "permissions": { "google": ["profile"] } } } }

  1. I've added source code with all commits with steps one by one to public repo on github. you can download it directly and check on your own => https://github.com/piotrzuzak/ionic-firebase-capacitor-test

PS. I've tried with 'phone' key adding but without success

Thank you in advance

baumblatt commented 4 years ago

Hi @piotrzuzak ,

Thank you by sharing your project, otherwise, I would never has figured out that the problem was rising on web tier before calling the native tier.

In your case, that use AngularFire, you need to init the Firebase App like described here: 4. Add Firebase config to environments variable 5. Setup @NgModule for the AngularFireModule

I look forward to hearing about your tests.

If you like this plugin, please don't forget to put a star the project to help others to find it.

Best regards, Bernardo Baumblatt

LeXXik commented 4 years ago

I have the same issue with the OP. I do not use Angular/React, as it is a an HTML5 canvas fullscreen game. One of the buttons initiate a Google sign in, which I use the following way:

//init
firebase.initializeApp({options});

// call
cfaSignIn('google.com').subscribe(function(user) {
    console.log(user);
});

// capacitor.confiig.json
"CapacitorFirebaseAuth": {
  "providers": ["google.com"],
  "languageCode": "en",
  "nativeAuth": false,
  "permissions": {}
}

EDIT: Here is some input from my logcat:

...
I/FirebaseInitProvider: FirebaseApp initialization successful
I/FacebookInitProvider: Failed to auto initialize the Facebook SDK
...
I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
...
D/Capacitor: Starting BridgeActivity
D/Capacitor: Registering plugin: App
...
D/Capacitor: Registering plugin: CapacitorFirebaseAuth
D/CapacitorFirebaseAuth: Verifying if the default FirebaseApp was initialized.
    Retrieving FirebaseAuth instance
    Initializing Google Provider
D/GoogleProviderHandler: Google Api is Available.
D/CapacitorFirebaseAuth: Google Provider Initialized
...
D/Capacitor: Loading app at http://localhost
...
D/Capacitor: Handling local request: http://localhost/
...
D/Capacitor/Plugin/LN: LocalNotification received: null
D/Capacitor/Plugin/LN: Activity started without notification attached
...
D/Capacitor: App started
D/Capacitor/Plugin/App: Firing change: true
V/Capacitor/Plugin/App: Notifying listeners for event appStateChange
D/Capacitor/Plugin/App: No listeners found for event appStateChange
V/FA: Activity resumed, time: 38378745
D/Capacitor: App resumed
...
D/Capacitor: Handling local request: http://localhost/start-script.js
...
E/Capacitor: JavaScript Error: {"type":"js.error","error":{"message":"Uncaught Error: Either an instance of firebase.auth.Auth must be passed as an argument to the firebase.auth.PhoneAuthProvider constructor, or the default firebase App instance must be initialized via firebase.initializeApp().","url":"http://localhost/start-script.js","line":7576,"col":7,"errorObject":"{\"code\":\"auth/argument-error\",\"message\":\"Either an instance of firebase.auth.Auth must be passed as an argument to the firebase.auth.PhoneAuthProvider constructor, or the default firebase App instance must be initialized via firebase.initializeApp().\"}"}}
E/Capacitor/Console: File: http://localhost/start-script.js - Line 7576 - Msg: Uncaught Error: Either an instance of firebase.auth.Auth must be passed as an argument to the firebase.auth.PhoneAuthProvider constructor, or the default firebase App instance must be initialized via firebase.initializeApp().
LeXXik commented 4 years ago

So, I guess the native layer is working fine and the problem is in the web layer? That error is coming from firebase-auth.js. I don't use Typescript, since my project is JS. This is my start-script.js where the app crashes:

"use strict";
exports.__esModule = true;

var auth = require("capacitor-firebase-auth");
auth.cfaSignIn('google.com').subscribe(function(user) { 
    console.log(user.displayName); 
  }
)

I tried to add <script src="firebase-app.js"></script> in the index.html and init with firebase.initializeApp({...}), but that gave an error that firebase is already defined. How do I satisfy @firebase/auth.js? Looking at the error and considering I don't use a phone provider for auth, it is missing a firebase initialization. However, I am not sure where and how to point it to the current instance.

LeXXik commented 4 years ago

Since my app is an HTML5 canvas game and the native layer seem to be working, I went ahead and boot up a local server to get a better look into the problem. The root cause was here image

I checked the line 30 in facades.js, which is here: https://github.com/baumblatt/capacitor-firebase-auth/blob/0461685f566a00e2e02f9b88237ccdcee9b746dd/src/alternative/alternative.ts#L27

So, the problem was that the Phone provider was initializing, regardless if I actually need it or not. I assume the crash was due to the phone provider missing a configuration? Not sure, and don't care, actually, since I only need Google sign-in.

So, instead of passing the auth provider id, using

"use strict";
exports.__esModule = true;

var auth = require("capacitor-firebase-auth");
auth.cfaSignIn('google.com').subscribe(function(user) { 
    console.log(user.displayName); 
  }
)

I call the google sign-in method directly:

"use strict";
exports.__esModule = true;

var auth = require("capacitor-firebase-auth");
auth.cfaSignInGoogle().subscribe(function(user) {
    console.log(user.displayName);
  }
)

It works now.

emaikongebm23 commented 3 years ago

hey @LeXXik, I got an error saying:

ERROR Error: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
    at Object.app (default~pages-authentication-authentication-module~user-user-module~web-es2015.js:366)
    at plugin.signIn.then (default~pages-authentication-authentication-module~user-user-module-es2015.js:75)
    at ZoneDelegate.invoke (polyfills-es2015.js:3470)
    at Object.onInvoke (vendor-es2015.js:64536)
    at ZoneDelegate.invoke (polyfills-es2015.js:3469)
    at Zone.run (polyfills-es2015.js:3229)
    at zone.scheduleMicroTask (polyfills-es2015.js:3963)
    at ZoneDelegate.invokeTask (polyfills-es2015.js:3505)
    at Object.onInvokeTask (vendor-es2015.js:64524)
    at ZoneDelegate.invokeTask (polyfills-es2015.js:3504)

Did you get this error too or am I missing something here?