Scandit / scandit-react-native-datacapture-barcode

0 stars 4 forks source link

Android app restart fails #6

Closed samzmann closed 2 years ago

samzmann commented 2 years ago

App restart is failing on Android, with the error:

Error: Exception in HostObject::get(propName:ScanditDataCaptureBarcodeSelection): java.lang.IllegalArgumentException: Cache for class class com.scandit.datacapture.barcode.selection.internal.module.capture.NativeSelectionType (Kotlin reflection is not available) contains no key com.scandit.datacapture.barcode.selection.internal.module.capture.NativeSelectionType$CppProxy@41d38ca

This happens when the bundler restarts the app (eg. if Fast refresh not possible), and when programmatically restarting the app (eg. with react-native-restart).

buildscript.ext (android/build.gradle):

ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 23
        compileSdkVersion = 30
        targetSdkVersion = 30
        androidXCore = "1.0.2"
        firebaseMessagingVersion = "21.1.0"
    }

See related iOS issue: https://github.com/Scandit/scandit-react-native-datacapture-barcode/issues/5

ScanditSupport commented 2 years ago

Hi @LaVielle,

Since this issue is related to the iOS one you mentioned and we replied in that thread already, I will close this one.

samzmann commented 2 years ago

Alrighty, if I take it one step back there is still an issue: Hot reload is not working.

To reproduce: git clone git@github.com:Scandit/datacapture-react-native-samples.git cd datacapture-react-native-samples/BarcodeCaptureSimpleSample yarn && yarn android

Then once the app is loaded, press r in the bundler terminal window. The reload fails with error:

 ERROR  Error: Exception in HostObject::get(propName:ScanditDataCaptureBarcodeSelection): java.lang.IllegalArgumentException: Cache for class class com.scandit.datacapture.barcode.selection.internal.module.capture.NativeSelectionType (Kotlin reflection is not available) contains no key com.scandit.datacapture.barcode.selection.internal.module.capture.NativeSelectionType$CppProxy@ebff87c
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. 
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. 
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

Then, if I do: yarn remove scandit-react-native-datacapture-barcode yarn remove scandit-react-native-datacapture-core

comment out excludeGroup "com.scandit.datacapture" in android/build.gradle

and simplify App.js to this:

import React, { Component } from 'react';
import { Text, View } from 'react-native'

export class App extends Component {

  render() {
    return (
      <View>
        <Text>Hello</Text>
      </View>
    );
  };
}

Then I get no error.

So I'm guessing there is something wrong somewhere in the Scandit lib.

Here is the output of yarn react-native info. Maybe you see some obvious misconfiguration in my environment that would explain solve the issue.

System:
    OS: macOS 12.1
    CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
    Memory: 43.37 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.3.0 - /var/folders/s0/gk_bhjhd26s04kj5ykzg791r0000gn/T/yarn--1641415396267-0.11052598532641689/node
    Yarn: 1.22.17 - /var/folders/s0/gk_bhjhd26s04kj5ykzg791r0000gn/T/yarn--1641415396267-0.11052598532641689/yarn
    npm: 8.3.0 - ~/.nvm/versions/node/v14.17.0/bin/npm
    Watchman: 2022.01.03.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0
    Android SDK:
      API Levels: 23, 27, 28, 29, 30
      Build Tools: 27.0.3, 28.0.3, 29.0.2, 30.0.2
      System Images: android-28 | Google APIs Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.7042882
    Xcode: 13.0/13A233 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_172 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1 
    react-native: 0.64.2 => 0.64.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
samzmann commented 2 years ago

@ScanditSupport any idea?

samzmann commented 2 years ago

Changing the inlineRequires config from false to true in metro.config.js seems to do the trick.

ScanditSupport commented 2 years ago

@LaVielle we're still looking into the details. Thanks for additional information.

ScanditSupport commented 2 years ago

@LaVielle we can confirm that your suggestion "Changing the inlineRequires config from false to true in metro.config.js" is a valid workaround. We will add a fix and further optimizations in the upcoming 6.11 version.

Best regards Scandit Support

ScanditSupport commented 2 years ago

@LaVielle we need to push the fix to a later version 6.11 is already in QA but the workaround "Changing the inlineRequires config from false to true" will be valid for 6.11.0

In case we shall notify you regarding the version with the fix, please reach out to us directly: https://support.scandit.com/hc/en-us

Best regards Scandit Support