tns-android version 5.4.0
angular: 8.0.0
nativescript: 8.0.0
nativescript-plugin-firebase: 8.3.2
tns-core-modules: ~5.4.0,
{
"external_push_client_only": false,
"using_ios": false,
"using_android": true,
"firestore": false,
"realtimedb": true,
"authentication": false,
"remote_config": false,
"performance_monitoring": false,
"messaging": false,
"in_app_messaging": false,
"crashlytics": true,
"crash_reporting": false,
"storage": false,
"functions": false,
"facebook_auth": false,
"google_auth": false,
"admob": false,
"invites": false,
"dynamic_links": false,
"ml_kit": false
}
app.component.ts
import * as firebase from "nativescript-plugin-firebase";
@Component({
selector: "ns-app",
moduleId: module.id,
templateUrl: "./app.component.html"
})
export class AppComponent implements OnInit{
ngOnInit(){ firebase.init().then(
() => {
console.log("firebase.init done");
},
error => {
console.error(`firebase.init error: ${error}`);
}
);}
}
then in a button on a tap event
addToQueue() {
console.log("adding to queue")
console.log(firebase)
const queue_n = 0
var update_value = {}
update_value[`customers_queue/${queue_n}/status/`] = "pending"
update_value[`customers_queue/${queue_n}/number/`] = queue_n
//update_value[`customers_queue/${queue_n}/timestamp/`] = firebase.ServerValue.TIMESTAMP
console.log(update_value)
firebase.update('/', update_value);
}
LOG from device Fica cel: firebase.init error: Firebase already initialized
LOG from device Fica cel: Error in firebase.init: TypeError: Cannot read property 'FirebaseAnalytics' of undefined
LOG from device Fica cel: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
LOG from device Fica cel: firebase.init error: TypeError: Cannot read property 'FirebaseAnalytics' of undefined
LOG from device Fica cel: {
LOG from device Fica cel: "initialized": true,
LOG from device Fica cel: adding to queue
LOG from device Fica cel: "instance": null,
LOG from device Fica cel: "currentAdditionalUserInfo": null,
LOG from device Fica cel: "authStateListeners": [],
LOG from device Fica cel: "_receivedNotificationCallback": null,
LOG from device Fica cel: "_dynamicLinkCallback": null,
LOG from device Fica cel: "admob": {
LOG from device Fica cel: "AD_SIZE": {
LOG from device Fica cel: "SMART_BANNER": "SMART",
LOG from device Fica cel: "LARGE_BANNER": "LARGE",
LOG from device Fica cel: "BANNER": "BANNER",
LOG from device Fica cel: "MEDIUM_RECTANGLE": "MEDIUM",
LOG from device Fica cel: "FULL_BANNER": "FULL",
LOG from device Fica cel: "firebaseRemoteConfig": null,
LOG from device Fica cel: "LEADERBOARD": "LEADERBOARD",
LOG from device Fica cel: "SKYSCRAPER": "SKYSCRAPER",
LOG from device Fica cel: "FLUID": "FLUID"
LOG from device Fica cel: }
LOG from device Fica cel: },
LOG from device Fica cel: "crashlytics": {},
LOG from device Fica cel: "analytics": {},
LOG from device Fica cel: "performance": {},
LOG from device Fica cel: "storage": {},
LOG from device Fica cel: "mlkit": {
LOG from device Fica cel: "textrecognition": {},
LOG from device Fica cel: "barcodescanning": {
LOG from device Fica cel: "1": "CODE_128",
LOG from device Fica cel: "BarcodeFormat": {
LOG from device Fica cel: "2": "CODE_39",
LOG from device Fica cel: "4": "CODE_93",
LOG from device Fica cel: "16": "DATA_MATRIX",
LOG from device Fica cel: "32": "EAN_13",
LOG from device Fica cel: "8": "CODABAR",
LOG from device Fica cel: "64": "EAN_8",
LOG from device Fica cel: "128": "ITF",
LOG from device Fica cel: "256": "QR_CODE",
LOG from device Fica cel: "512": "UPC_A",
LOG from device Fica cel: "1024": "UPC_E",
LOG from device Fica cel: "2048": "PDF417",
LOG from device Fica cel: "4096": "AZTEC",
LOG from device Fica cel: "CODE_128": 1,
LOG from device Fica cel: "C...
LOG from device Fica cel: {
LOG from device Fica cel: "customers_queue/0/status/": "pending",
LOG from device Fica cel: "customers_queue/0/number/": 0
LOG from device Fica cel: }
LOG from device Fica cel: ERROR Error: Uncaught (in promise): Run init() first!
I tried to delete the node_modules, platforms and reconfig firebase with no success
if I uncomment this line
update_value[customers_queue/${queue_n}/timestamp/] = firebase.ServerValue.TIMESTAMP
then i get an error saying that cant read Timestamp of undefined.
Hi. I'm having the same issue here. Did you find a working way?
I'm also having the same issue too.
Waiting for any response.. (I have the same problem)
As usual: share a repo and I might take a look.
I have the same problem but unfortunately I can't share the repo but I think these are enough.
My main.js
import Vue from 'nativescript-vue'
import VueDevtools from 'nativescript-vue-devtools'
import firebase from 'nativescript-plugin-firebase'
import * as appSettings from 'tns-core-modules/application-settings'
import store from './store/main'
import App from './components/App'
if (TNS_ENV !== 'production') {
Vue.use(VueDevtools)
}
// Prints Vue logs when --env.production is *NOT* set while building
Vue.config.silent = (TNS_ENV === 'production')
firebase.init({
// Optionally pass in properties for database, authentication and cloud messaging,
// see their respective docs.
}).then(
() => {
// eslint-disable-next-line no-console
console.log('firebase.init done')
},
(error) => {
// eslint-disable-next-line no-console
console.log(`firebase.init error: ${error}`)
},
)
Vue.registerElement("MLKitBarcodeScanner", () => require("nativescript-plugin-firebase/mlkit/barcodescanning").MLKitBarcodeScanner)
new Vue({
store,
appSettings,
render: (h) => h('frame', [h(App)]),
}).$start()
And the error is the following
System.err: An uncaught Exception occurred on "main" thread.
System.err: Unable to start activity ComponentInfo{MY_APP_ID/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
System.err: TypeError: Cannot read property 'FirebaseAnalytics' of undefined
System.err:
System.err: StackTrace:
System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{MY_APP_ID/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
System.err: TypeError: Cannot read property 'FirebaseAnalytics' of undefined
System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2916)
System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3051)
System.err: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
System.err: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1811)
System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
System.err: at android.os.Looper.loop(Looper.java:193)
System.err: at android.app.ActivityThread.main(ActivityThread.java:6694)
System.err: at java.lang.reflect.Method.invoke(Native Method)
System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
System.err: Caused by: com.tns.NativeScriptException: Calling js method onCreate failed
System.err: TypeError: Cannot read property 'FirebaseAnalytics' of undefined
System.err: at com.tns.Runtime.callJSMethodNative(Native Method)
System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1209)
System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:1096)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1083)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1063)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1055)
System.err: at com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:19)
System.err: at android.app.Activity.performCreate(Activity.java:7136)
System.err: at android.app.Activity.performCreate(Activity.java:7127)
System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2896)
System.err: ... 11 more
@gcacoutinho You are having this error because you have not install the package very well. You have to uninstall the package delete the platform folder and re-install the package.
After this navigate $ cd node-modules/nativescript-plugin-firebase and run this command
$ npm run config
A prompt will display with options. You can accept according to your preferred use case using the y/n on your terminal.
After this you will have to update the firebase-nativescript.json this file contain settings of the features you will be using with your application.
Note: you must uninstall the previous package (because on init has already compile alot under the hood) if you already ran the $ tns run android or iOS command. You must also delete the platform or clear the overall cached. But i strongly recommend delete the platform folder.
@delino12 thanks for the quick response
this is my firebase.nativescript.json
{
"external_push_client_only": false,
"using_ios": true,
"using_android": true,
"analytics": false,
"firestore": false,
"realtimedb": false,
"authentication": false,
"remote_config": false,
"performance_monitoring": false,
"messaging": false,
"in_app_messaging": false,
"crashlytics": false,
"storage": false,
"functions": false,
"facebook_auth": false,
"google_auth": false,
"admob": false,
"dynamic_links": false,
"ml_kit": true,
"ml_kit_text_recognition": false,
"ml_kit_barcode_scanning": true,
"ml_kit_face_detection": false,
"ml_kit_image_labeling": false,
"ml_kit_object_detection": false,
"ml_kit_custom_model": false,
"ml_kit_natural_language_identification": false,
"ml_kit_natural_language_translation": false,
"ml_kit_natural_language_smartreply": false
}
I think it looks fine but I'll delete and configure it again, since it could also be the cache causing the problem.
It's working fine now, I forgot to add the meta-data to my AndroidManifest.xml
The meta-data I am referring to (in my case):
<meta-data android:name="com.google.firebase.ml.vision.DEPENDENCIES"
android:value="barcode" />
NOTE: this is printed in the end of the firebase configuration script and varies accordingly
I have this error, I did what they recommend here but it didn't work for me.
@LuisSarmientoM Can you please upgrade to 10.0.2 and see if that helps?
Most helpful comment
It's working fine now, I forgot to add the
meta-datato myAndroidManifest.xmlThe
meta-dataI am referring to (in my case):NOTE: this is printed in the end of the firebase configuration script and varies accordingly