aclec / expo-zebra-scanner

14 stars 6 forks source link

Default FirebaseApp is not initialized in this process com.symbol.datawedge.ACTION_BARCODE_SCANNED. #7

Closed creen-aps closed 1 year ago

creen-aps commented 1 year ago

I do not use firebase, my app sometimes crash, with thsi error. (react native 0.72 eso custom build) Your app just crashed. See the error below.

java.lang.RuntimeException: An error occurred while executing doInBackground()
  android.os.AsyncTask$4.done(AsyncTask.java:399)
  java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
  java.util.concurrent.FutureTask.setException(FutureTask.java:252)
  java.util.concurrent.FutureTask.run(FutureTask.java:271)
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
  java.lang.Thread.run(Thread.java:919)
Caused by java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.symbol.datawedge.ACTION_BARCODE_SCANNED. Make sure to call FirebaseApp.initializeApp(Context) first.
  com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:183)
  com.google.firebase.messaging.FirebaseMessaging.getInstance(com.google.firebase:firebase-messaging@@21.1.0:1)
  com.wix.reactnativenotifications.fcm.FcmToken.refreshToken(FcmToken.java:75)
  com.wix.reactnativenotifications.fcm.FcmToken.onAppReady(FcmToken.java:65)
  com.wix.reactnativenotifications.fcm.FcmInstanceIdRefreshHandlerService.onHandleWork(FcmInstanceIdRefreshHandlerService.java:26)
  androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:396)
  androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:387)
  android.os.AsyncTask$3.call(AsyncTask.java:378)
  java.util.concurrent.FutureTask.run(FutureTask.java:266)
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
  java.lang.Thread.run(Thread.java:919)
aclec commented 1 year ago

Hi,

Disable default profile in DataWedge and create a profile for your app.

creen-aps commented 1 year ago

It is already default and only profile in DataWedge.

aclec commented 1 year ago

No you need to disable default profile and create a new one for your expo app.

creen-aps commented 1 year ago

Sorry, I did not explain clearly. My profile is the only one in DataWedge.

aclec commented 1 year ago

Is it a new one with only your expo app specify ?

Someone get an error like this when he was using the default profile in Datawedge.

aclec commented 1 year ago

If it doesn't resolve the problem, Check that you're in Expo 49 and rebuild your development build. I never got this error in my all apps, it seems the problem come from Firebase check on this, I have no other idea.

aclec commented 1 year ago

Are you running the code 2 times and create multiple listener ? It could be an error too.

creen-aps commented 1 year ago

I use reusable component with multiple inputs, it works, but sometime app crash.

    import React, { useEffect, useState, useRef } from 'react'
import { TextInput, StyleSheet, View, Text } from 'react-native'
import * as ExpoZebraScanner from 'expo-zebra-scanner'

type ZebraScannerInputProps = {
  value: string
  onChange: (value: string) => void
  helperText?: string
  error?: boolean
  placeholder: string
}

const ZebraScannerInput: React.FC<ZebraScannerInputProps> = ({
  value,
  onChange,
  helperText,
  error = false,
  placeholder,
}) => {
  const [isActive, setIsActive] = useState(false)
  const [isFocused, setIsFocused] = useState(false)
  const inputRef = useRef(null)

  useEffect(() => {
    const listener = ExpoZebraScanner.addListener((event) => {
      if (isActive && event.scanData) {
        onChange(event.scanData)
      }
    })

    return () => {
      ExpoZebraScanner.removeListener(listener)
    }
  }, [isActive, onChange])

  return (
    <View style={styles.inputContainer}>
      {isFocused && helperText && (
        <Text style={styles.helperText}>{helperText}</Text>
      )}
      <TextInput
        ref={inputRef}
        style={[
          styles.input,
          isFocused && { borderColor: '#1E88E5' },
          error && { borderColor: 'red' },
        ]}
        value={value}
        onChangeText={onChange}
        onFocus={() => {
          setIsFocused(true)
          setIsActive(true)
        }}
        onBlur={() => {
          setIsFocused(false)
          setIsActive(false)
        }}
        placeholder={placeholder}
      />
    </View>
  )
}

const styles = StyleSheet.create({
  inputContainer: {

  },
  input: {

  },
  helperText: {

  },
})

export default ZebraScannerInput
aclec commented 1 year ago

I think you should not do that. If you're app listen the same Intent in 2 components at same time, I think that could crash the app.

Try to wrap the listener and the return function in the if(isActive).

aclec commented 1 year ago

Is it working ?

creen-aps commented 1 year ago

I can't reproduce anymore.