EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 446 forks source link

TypeError: Cannot read property 'android' of undefined #1327

Open boriswinner opened 5 years ago

boriswinner commented 5 years ago

Hello! I'm trying to add Firebase Auth to my nativescript vue project.

When I add the init to my main.js:

var firebase = require("nativescript-plugin-firebase");
firebase
  .init({
    // Optionally pass in properties for database, authentication and cloud messaging,
    // see their respective docs.
  })
  .then(
    function(instance) {
      console.log("firebase.init done");
    },
    function(error) {
      console.log("firebase.init error: " + error);
    }
  );

I get the following error:

An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: 

Error calling module function 

TypeError: Cannot read property 'android' of undefined
File: "file:///data/data/org.boriswinner.teendok/files/app/vendor.js, line: 18175, column: 26

StackTrace: 
 Frame: function:'../node_modules/nativescript-plugin-firebase/mlkit/barcodescanning/index.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 18175, column: 27
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'../node_modules/nativescript-plugin-firebase/mlkit/index.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 19085, column: 23
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'../node_modules/nativescript-plugin-firebase/firebase-common.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 14701, column: 13
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'../node_modules/nativescript-plugin-firebase/firebase.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 15010, column: 25
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 1447, column: 18
 Frame: function:'./main.js', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 1464, column: 30
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'checkDeferredModules', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 45, column: 23
 Frame: function:'', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 149, column: 18
 Frame: function:'', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 152, column: 10
 Frame: function:'require', file:'', line: 1, column: 266

TypeError: Cannot read property 'android' of undefined
File: "<unknown>, line: 1, column: 265

StackTrace: 
 Frame: function:'../node_modules/nativescript-plugin-firebase/mlkit/barcodescanning/index.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 18175, column: 27
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'../node_modules/nativescript-plugin-firebase/mlkit/index.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 19085, column: 23
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'../node_modules/nativescript-plugin-firebase/firebase-common.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 14701, column: 13
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'../node_modules/nativescript-plugin-firebase/firebase.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 15010, column: 25
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 1447, column: 18
 Frame: function:'./main.js', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 1464, column: 30
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'checkDeferredModules', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 45, column: 23
 Frame: function:'', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 149, column: 18
 Frame: function:'', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 152, column: 10
 Frame: function:'require', file:'', line: 1, column: 266

 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5832)
 at android.app.ActivityThread.-wrap1(Unknown Source:0)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1685)
 at android.os.Handler.dispatchMessage(Handler.java:106)
 at android.os.Looper.loop(Looper.java:173)
 at android.app.ActivityThread.main(ActivityThread.java:6653)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:821)
Caused by: com.tns.NativeScriptException: 

Error calling module function 

TypeError: Cannot read property 'android' of undefined
File: "file:///data/data/org.boriswinner.teendok/files/app/vendor.js, line: 18175, column: 26

StackTrace: 
 Frame: function:'../node_modules/nativescript-plugin-firebase/mlkit/barcodescanning/index.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 18175, column: 27
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'../node_modules/nativescript-plugin-firebase/mlkit/index.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 19085, column: 23
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'../node_modules/nativescript-plugin-firebase/firebase-common.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 14701, column: 13
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'../node_modules/nativescript-plugin-firebase/firebase.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 15010, column: 25
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 1447, column: 18
 Frame: function:'./main.js', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 1464, column: 30
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'checkDeferredModules', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 45, column: 23
 Frame: function:'', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 149, column: 18
 Frame: function:'', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 152, column: 10
 Frame: function:'require', file:'', line: 1, column: 266

TypeError: Cannot read property 'android' of undefined
File: "<unknown>, line: 1, column: 265

StackTrace: 
 Frame: function:'../node_modules/nativescript-plugin-firebase/mlkit/barcodescanning/index.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 18175, column: 27
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'../node_modules/nativescript-plugin-firebase/mlkit/index.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 19085, column: 23
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'../node_modules/nativescript-plugin-firebase/firebase-common.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 14701, column: 13
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'../node_modules/nativescript-plugin-firebase/firebase.js', file:'file:///data/data/org.boriswinner.teendok/files/app/vendor.js', line: 15010, column: 25
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 1447, column: 18
 Frame: function:'./main.js', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 1464, column: 30
 Frame: function:'__webpack_require__', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 76, column: 30
 Frame: function:'checkDeferredModules', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 45, column: 23
 Frame: function:'', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 149, column: 18
 Frame: function:'', file:'file:///data/data/org.boriswinner.teendok/files/app/bundle.js', line: 152, column: 10
 Frame: function:'require', file:'', line: 1, column: 266

 at com.tns.Runtime.runModule(Native Method)
 at com.tns.Runtime.runModule(Runtime.java:624)
 at com.tns.Runtime.run(Runtime.java:616)
 at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
 at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1120)
 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5829)
 ... 8 more

What's wrong? Here is the repo with my code: https://github.com/boriswinner/teendok-ns/tree/auth

boriswinner commented 5 years ago

Also tried with firebase plugin version 8.3.2, still crashes

EddyVerbruggen commented 5 years ago

I don't see a firebase.nativescript.json in that repo.

boriswinner commented 5 years ago

I don't see a firebase.nativescript.json in that repo.

Yep, there is no such file in the repo. But why? I've installed the plugin using the command from README. When I now type tns plugin add nativescript-plugin-firebase again, it says: Plugin "nativescript-plugin-firebase" is already installed. There is a "nativescript-plugin-firebase" folder in /node_modules with some files and directories.

Also, I was not prompted anything during the installation (tns plugin add nativescript-plugin-firebase)

boriswinner commented 5 years ago

Also:

teendok-ns/teendok-ns/node_modules/nativescript-plugin-firebase (auth)
$ npm run config

> nativescript-plugin-firebase@9.0.2 config C:\Users\Lenovo\Documents\teendok-ns\teendok-ns\node_modules\nativescript-plugin-firebase
> node scripts/postinstall.js config

NativeScript Firebase Plugin Installation
No existing firebase.nativescript.json config file found and terminal is not interactive! Default configuration will be used.
EddyVerbruggen commented 5 years ago

That line "terminal is not interactive" is the key here. What kind of Terminal / command prompt are you using? Can you try a standard one if you're not already? Otherwise, you'll have to craft that file by hand (I can help with that).

boriswinner commented 5 years ago

That line "terminal is not interactive" is the key here. What kind of Terminal / command prompt are you using? Can you try a standard one if you're not already? Otherwise, you'll have to craft that file by hand (I can help with that).

I was using Git Bash. I tried again with windows terminal, turned off most of the features including mlkit. There is still no firebase.nativescript.json in repo, but the app starts correctly now (firebase init done). Thank you a lot for your help!

But anyway, why did not it work out of the box with default config (with more features turned on)?

VACKOM commented 4 years ago

@EddyVerbruggen . I recently downloaded your firebase plugin (great job) and I am using it for text recognition. After I use my phone camera to take a picture and click on the button for the text recognition code to give me the text in the images, i receive this error "Cannot read property 'android' undefined" Can you please help?

manojdcoder commented 4 years ago

@VACKOM Can you share a sample project?

VACKOM commented 4 years ago

@manojdcoder Kindly click on the link below for a sample project with error

https://github.com/VACKOM/image-textrecognition/tree/master

Thank you for your assistance.

manojdcoder commented 4 years ago

@VACKOM recognizeTextOnDevice({...}) method expects ImageSource. It may accept Image only if you set imageSource instead of src. With your current code, it tries to extract ImageSource from Image but fails as you set src.

myImage.src = imageSourceModule.fromFileOrResource("res://back")

With above change, if you hit check text you will see 150 x 150 as result from Firebase.

Also there seems to be an issue with Camera plugin on my device (Android 10), the image fails as the camera module fails to write the image in the anticipated path. If you too have similar issue, you must raise an issue on Camera plugin.

VACKOM commented 4 years ago

@manojdcoder Thank you so much. The plugin is working perfectly.