mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
7.51k stars 1.09k forks source link

App crashes in release mode🐛 #954

Closed palagonKevo closed 1 year ago

palagonKevo commented 2 years ago

What were you trying to do?

I'm trying to assemble the release apk.

Reproduceable Code

Just cd android/ and then ./gradlew assembleRelease.

This are the dependencies:

node: v16.13.0
react-native: 6.4.0
os: Ubuntu 21.10
react-native-vision-camera: ^2.13.1
vision-camera-dynamsoft-barcode-reader: ^0.3.1

babel config:
module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    ["module:react-native-dotenv", {
      "moduleName": "@env",
      "path": ".env",
      "blacklist": null,
      "whitelist": null,
      "safe": false,
      "allowUndefined": true
    }],
    [
      'react-native-reanimated/plugin',
      {
        globals: ['__decode'],
      },
    ]
  ],
  env: {
    production: {
      plugins: ['react-native-paper/babel','react-native-reanimated/plugin'],
    },
  },
};

What happened instead?

When it's built, and when trying to use the camera, the apk crashes every time. This works perfectly on debug mode.

Relevant log output

This is what I get from adb logcat *:S ReactNative:V ReactNativeJS:V.

03-31 09:50:25.553 18158 18187 E ReactNativeJS: ReferenceError: Property '__decode' doesn't exist, js engine: hermes
03-31 09:50:25.554 18158 18187 E ReactNativeJS: TypeError: Cannot read property 'decode' of undefined
03-31 09:50:25.554 18158 18187 E ReactNativeJS: 
03-31 09:50:25.554 18158 18187 E ReactNativeJS: This error is located at:
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in RCTView
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in v
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in RNSScreen
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in R
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in D
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in B
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in h
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in RNSScreenStack
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in ScreenStack
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in y
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in RNCSafeAreaProvider
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in y
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in D
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in l
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in RCTView
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in RCTView
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in b, js engine: hermes
03-31 09:50:25.555 18158 18187 E ReactNativeJS: TypeError: Cannot read property 'decode' of undefined
03-31 09:50:25.555 18158 18187 E ReactNativeJS: 
03-31 09:50:25.555 18158 18187 E ReactNativeJS: This error is located at:
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in RCTView
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in v
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in RNSScreen
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in R
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in D
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in B
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in h
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in RNSScreenStack
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in ScreenStack
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in y
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in RNCSafeAreaProvider
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in y
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in D
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in l
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in RCTView
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in RCTView
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in b, js engine: hermes

Device

Mi Note 10 Pro

VisionCamera Version

2.13.1

Additional information

mrousavy commented 2 years ago

Hey, can you share your function decode and your useFrameProcessor?

palagonKevo commented 2 years ago

I've followed this steps: https://www.dynamsoft.com/codepool/react-native-qr-code-scanner-vision-camera.html There's all I've done this far.

mrousavy commented 2 years ago

did you add the native plugin as mentioned in that article? it looks to me like the native plugin is not correctly registered. As I said earlier, please share your code. I cannot see your screen from where I'm sitting.

Also, please share the initial logs that are logged by VisionCamera to Logcat on app-start, it says "Registering Plugins" or something like that.

maybe @xulihang has an idea?

xulihang commented 2 years ago

This seems to be related to proguard. Have you enabled proguard?

Try to add the following rules:

-keep class com.swmansion.reanimated.** { *; }
-keep class com.facebook.react.turbomodule.** { *; }
-keep class com.dynamsoft.dbr.** { *; }
palagonKevo commented 2 years ago

I've just tried adding those rules as I have enableProguardInReleaseBuilds enabled, so that would make sense, but it's not working. This is the code:

MainApplication.java: import com.visioncameradynamsoftbarcodereader.VisionCameraDynamsoftBarcodeReaderPackage; ... public class MainApplication extends Application implements ReactApplication { ... @Override protected List<ReactPackage> getPackages() { @SuppressWarnings("UnnecessaryLocalVariable") List<ReactPackage> packages = new PackageList(this).getPackages(); // Packages that cannot be autolinked yet can be added manually here, for example: packages.add(new VisionCameraDynamsoftBarcodeReaderPackage()); return packages; } android/app/build.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation. If none specified and
 *   // "index.android.js" exists, it will be used. Otherwise "index.js" is
 *   // default. Can be overridden with ENTRY_FILE environment variable.
 *   entryFile: "index.android.js",
 *
 *   // https://reactnative.dev/docs/performance#enable-the-ram-format
 *   bundleCommand: "ram-bundle",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    enableHermes: true,  // clean and rebuild if changing
    //bundleCommand: "ram-bundle",
]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = true

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = true

/**
 * The preferred build flavor of JavaScriptCore.
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US.  Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'

/**
 * Whether to enable the Hermes VM.
 *
 * This should be set on project.ext.react and mirrored here.  If it is not set
 * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
 * and the benefits of using Hermes will therefore be sharply reduced.
 */
def enableHermes = project.ext.react.get("enableHermes", false);

/**
 * Architectures to build native code for in debug.
 */
def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures")

android {
    ndkVersion rootProject.ext.ndkVersion

    compileSdkVersion rootProject.ext.compileSdkVersion

    dexOptions {
        javaMaxHeapSize "8g"
    }
    lintOptions {
        checkReleaseBuilds false
    }
    defaultConfig {
        resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
        applicationId "com.sukaiapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        missingDimensionStrategy 'react-native-camera', 'mlkit'
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk true  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
            if (nativeArchitectures) {
                ndk {
                    abiFilters nativeArchitectures.split(',')
                }
            }
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        defaultConfig.versionCode * 1000 + versionCodes.get(abi)
            }

        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'com.facebook.fresco:animated-base-support:1.3.0'

    implementation project(':react-native-code-push')
    implementation project(':react-native-svg')

    // For animated GIF support
    implementation 'com.facebook.fresco:animated-gif:2.5.0'

    // For WebP support, including animated WebP
    implementation 'com.facebook.fresco:animated-webp:2.5.0'
    implementation 'com.facebook.fresco:webpsupport:2.5.0'

    // For WebP support, without animations
    implementation 'com.facebook.fresco:webpsupport:2.5.0'
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
    implementation 'androidx.camera:camera-core:1.0.0'

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.fbjni'
    }

    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.implementation
    into 'libs'
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"`

ProductScanRNCamera.js (my react-native component):

...
const frameProcessor = useFrameProcessor((frame) => {
    'worklet'
    const config = {}
    config.template="{\"ImageParameter\":{\"BarcodeFormatIds\":[\"BF_QR_CODE\"],\"Description\":\"\",\"Name\":\"Settings\"},\"Version\":\"3.0\"}" //scan qrcode only

    const results = decode(frame,{})
    REA.runOnJS(setBarcodeResults)(results)
  }, [])
...
<Camera
  style={StyleSheet.absoluteFill}
  device={devices[device]}
  isActive={!modalVisible}
  //isActive={true}
  frameProcessor={frameProcessor}
  frameProcessorFps={5}
  />
...

What I got from logcat of app filtering by VisionCamera : `

03-31 08:26:42.771 29597 29597 F DEBUG   :       #10 pc 000000000008b7a4  /data/app/~~sGVw7Sze-gwsEFdM0_IFXQ==/com.sukaiapp-LeUSuDNCcz2NBnegkgw5vA==/base.apk!libVisionCamera.so (offset 0x1488000) (BuildId: 5dd67c20943092f7f7d69b80d1e8965a03c35317)
03-31 08:26:42.771 29597 29597 F DEBUG   :       #11 pc 000000000008b71c  /data/app/~~sGVw7Sze-gwsEFdM0_IFXQ==/com.sukaiapp-LeUSuDNCcz2NBnegkgw5vA==/base.apk!libVisionCamera.so (offset 0x1488000) (BuildId: 5dd67c20943092f7f7d69b80d1e8965a03c35317)
03-31 08:26:42.771 29597 29597 F DEBUG   :       #12 pc 000000000008b6d0  /data/app/~~sGVw7Sze-gwsEFdM0_IFXQ==/com.sukaiapp-LeUSuDNCcz2NBnegkgw5vA==/base.apk!libVisionCamera.so (offset 0x1488000) (BuildId: 5dd67c20943092f7f7d69b80d1e8965a03c35317)
03-31 08:26:42.771 29597 29597 F DEBUG   :       #13 pc 000000000008b6a8  /data/app/~~sGVw7Sze-gwsEFdM0_IFXQ==/com.sukaiapp-LeUSuDNCcz2NBnegkgw5vA==/base.apk!libVisionCamera.so (offset 0x1488000) (BuildId: 5dd67c20943092f7f7d69b80d1e8965a03c35317)
03-31 08:26:42.771 29597 29597 F DEBUG   :       #14 pc 000000000008a560  /data/app/~~sGVw7Sze-gwsEFdM0_IFXQ==/com.sukaiapp-LeUSuDNCcz2NBnegkgw5vA==/base.apk!libVisionCamera.so (offset 0x1488000) (BuildId: 5dd67c20943092f7f7d69b80d1e8965a03c35317)
03-31 08:26:42.771 29597 29597 F DEBUG   :       #15 pc 00000000000cac60  /data/app/~~sGVw7Sze-gwsEFdM0_IFXQ==/com.sukaiapp-LeUSuDNCcz2NBnegkgw5vA==/base.apk!libVisionCamera.so (offset 0x1488000) (BuildId: 5dd67c20943092f7f7d69b80d1e8965a03c35317)
03-31 08:26:42.771 29597 29597 F DEBUG   :       #16 pc 00000000000c6f90  /data/app/~~sGVw7Sze-gwsEFdM0_IFXQ==/com.sukaiapp-LeUSuDNCcz2NBnegkgw5vA==/base.apk!libVisionCamera.so (offset 0x1488000) (std::__ndk1::function<void ()>::operator()() const+20) (BuildId: 5dd67c20943092f7f7d69b80d1e8965a03c35317)
03-31 08:26:42.771 29597 29597 F DEBUG   :       #17 pc 00000000000c6b6c  /data/app/~~sGVw7Sze-gwsEFdM0_IFXQ==/com.sukaiapp-LeUSuDNCcz2NBnegkgw5vA==/base.apk!libVisionCamera.so (offset 0x1488000) (vision::VisionCameraScheduler::triggerUI()+44) (BuildId: 5dd67c20943092f7f7d69b80d1e8965a03c35317)
03-31 08:26:42.771 29597 29597 F DEBUG   :       #18 pc 00000000000cafa8  /data/app/~~sGVw7Sze-gwsEFdM0_IFXQ==/com.sukaiapp-LeUSuDNCcz2NBnegkgw5vA==/base.apk!libVisionCamera.so (offset 0x1488000) (facebook::jni::detail::MethodWrapper<void (vision::VisionCameraScheduler::*)(), &(vision::VisionCameraScheduler::triggerUI()), vision::VisionCameraScheduler, void>::dispatch(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<vision::VisionCameraScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*>)+156) (BuildId: 5dd67c20943092f7f7d69b80d1e8965a03c35317)
03-31 08:26:42.771 29597 29597 F DEBUG   :       #19 pc 00000000000cb018  /data/app/~~sGVw7Sze-gwsEFdM0_IFXQ==/com.sukaiapp-LeUSuDNCcz2NBnegkgw5vA==/base.apk!libVisionCamera.so (offset 0x1488000) (facebook::jni::detail::CallWithJniConversions<void (*)(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<vision::VisionCameraScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*>), void, facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<vision::VisionCameraScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*>::call(facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<vision::VisionCameraScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*, void (*)(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<vision::VisionCameraScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*>))+56) (BuildId: 5dd67c20943092f7f7d69b80d1e8965a03c35317)
03-31 08:26:42.771 29597 29597 F DEBUG   :       #20 pc 00000000000cae7c  /data/app/~~sGVw7Sze-gwsEFdM0_IFXQ==/com.sukaiapp-LeUSuDNCcz2NBnegkgw5vA==/base.apk!libVisionCamera.so (offset 0x1488000) (facebook::jni::detail::FunctionWrapper<void (*)(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<vision::VisionCameraScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*>), facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<vision::VisionCameraScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*, void>::call(_JNIEnv*, _jobject*, void (*)(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<vision::VisionCameraScheduler, facebook::jni::detail::BaseHybridClass>::JavaPart, facebook::jni::JObject, void>::_javaobject*>))+48) (BuildId: 5dd67c20943092f7f7d69b80d1e8965a03c35317)
03-31 08:26:42.771 29597 29597 F DEBUG   :       #21 pc 00000000000c7094  /data/app/~~sGVw7Sze-gwsEFdM0_IFXQ==/com.sukaiapp-LeUSuDNCcz2NBnegkgw5vA==/base.apk!libVisionCamera.so (offset 0x1488000) (facebook::jni::detail::MethodWrapper<void (vision::VisionCameraScheduler::*)(), &(vision::VisionCameraScheduler::triggerUI()), vision::VisionCameraScheduler, void>::call(_JNIEnv*, _jobject*)+36) (BuildId: 5dd67c20943092f7f7d69b80d1e8965a03c35317)
03-31 08:26:42.771 29597 29597 F DEBUG   :       #23 pc 0000000002092ed8  /memfd:jit-cache (deleted) (offset 0x2000000) (com.mrousavy.camera.frameprocessor.VisionCameraScheduler.lambda$OIBIZgFLjVdge_4-pqhpIJ7V8NA+40)
03-31 08:26:42.771 29597 29597 F DEBUG   :       #30 pc 0000000000059510  [anon:dalvik-classes2.dex extracted in memory from /data/app/~~sGVw7Sze-gwsEFdM0_IFXQ==/com.sukaiapp-LeUSuDNCcz2NBnegkgw5vA==/base.apk!classes2.dex] (com.mrousavy.camera.frameprocessor.-$$Lambda$VisionCameraScheduler$OIBIZgFLjVdge_4-pqhpIJ7V8NA.run+4)
03-31 11:42:36.240 26444 26492 I VisionCamera: Initializing FrameProcessorRuntimeManager...
03-31 11:42:36.240 26444 26492 I VisionCamera: Initializing Vision JS-Runtime...
03-31 11:42:36.242 26444 26492 I VisionCamera: Initialized Vision JS-Runtime!
03-31 11:42:36.242 26444 26492 I VisionCamera: Installing Frame Processor Plugin "__decode"...
03-31 11:42:36.242 26444 26492 I VisionCamera: Installing Frame Processor Plugin "__decode"...
03-31 11:42:36.435 26444 26485 I VisionCamera: Installing JSI bindings...
03-31 11:42:36.435 26444 26485 I VisionCamera: Finished installing JSI bindings!`
xulihang commented 2 years ago

Try to disable proguard first. If the error still exists, it is not related to proguard.

xulihang commented 2 years ago

In my case, when I run the example with proguard disabled, it works fine.

But when I enabled proguard, there is a worklet error even after I have added proguard rules.

palagonKevo commented 2 years ago

Seem to be related with proguard, but I need it if I wanna shared this app.

xulihang commented 2 years ago

Vision camera may also need adding rules. I find a commit about this: https://github.com/mrousavy/react-native-vision-camera/pull/465/files

palagonKevo commented 2 years ago

I've just found that one as well, it's building, let see if that works. .

palagonKevo commented 2 years ago

Na, I'm trying this rules:

-keep class com.swmansion.reanimated.** { *; }
-keep class androidx.camera.extensions.** {*;}
-keep class com.facebook.react.turbomodule.** { *; }
-keep class com.dynamsoft.dbr.** { *; }
-keep class com.facebook.hermes.unicode.** { *; }
-keep class com.facebook.jni.** { *; }

But nothing seems to be solving the problem.

xulihang commented 2 years ago

I've managed to solve this by adding the rules mentioned in this Xamarin project: https://github.com/JimmyPun610/BarcodeScanner.XF

The following rule is also needed:

-keep class androidx.camera.core.** {*;}
palagonKevo commented 2 years ago

Same error with crash.

xulihang commented 2 years ago

What is the error message? My build works fine with the following rules:

-keep class com.swmansion.reanimated.** { *; }
-keep class com.facebook.react.turbomodule.** { *; }
-keep class com.dynamsoft.dbr.** { *; }
-keep class androidx.camera.core.** {*;}
palagonKevo commented 2 years ago

The error is the same as the last one, like this one:

03-31 09:50:25.553 18158 18187 E ReactNativeJS: ReferenceError: Property '__decode' doesn't exist, js engine: hermes
03-31 09:50:25.554 18158 18187 E ReactNativeJS: TypeError: Cannot read property 'decode' of undefined
03-31 09:50:25.554 18158 18187 E ReactNativeJS: 
03-31 09:50:25.554 18158 18187 E ReactNativeJS: This error is located at:
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in RCTView
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in v
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in RNSScreen
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in R
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in D
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in B
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in h
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in RNSScreenStack
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in ScreenStack
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in y
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in RNCSafeAreaProvider
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in y
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in D
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in l
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in RCTView
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in RCTView
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.554 18158 18187 E ReactNativeJS:     in b, js engine: hermes
03-31 09:50:25.555 18158 18187 E ReactNativeJS: TypeError: Cannot read property 'decode' of undefined
03-31 09:50:25.555 18158 18187 E ReactNativeJS: 
03-31 09:50:25.555 18158 18187 E ReactNativeJS: This error is located at:
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in RCTView
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in v
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in RNSScreen
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in R
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in D
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in B
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in h
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in RNSScreenStack
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in ScreenStack
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in y
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in RNCSafeAreaProvider
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in y
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in D
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in l
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in RCTView
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in RCTView
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in Unknown
03-31 09:50:25.555 18158 18187 E ReactNativeJS:     in b, js engine: hermes
xulihang commented 2 years ago

Then I have no idea what the reason is. Maybe you can examine your project with my example: https://github.com/xulihang/vision-camera-dynamsoft-barcode-reader/tree/main/example

palagonKevo commented 2 years ago

It seem that when minifying the project, the apk doesn't recognize the decode function, the one included here: import { DBRConfig, decode, TextResult } from 'vision-camera-dynamsoft-barcode-reader' An after I try to open the camera, it crashes. That's what I understood from the error, which is kinda strange because it works as it should with the debug mode.

mrousavy commented 2 years ago

Minifying? Are you using a custom minifyer? That might be the reason because it renames functions like __decode(..) to a(..)!

palagonKevo commented 2 years ago

By minify I mean this

release {
   ...
    minifyEnabled enableProguardInReleaseBuilds
    proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
iskezil commented 1 year ago

Is there a solution to the problem?

mrousavy commented 1 year ago

Hey! I've rewritten the entire Android codebase of VisionCamera from CameraX to Camera2 in the efforts of ✨ VisionCamera V3.

I just now completed the Camera2 rewrite and I believe the core structure is running, but there might be some edge cases to iron out. Can you try and test the PR #1674 for me to see if you can still reproduce this issue here?

Here's an instruction on how you can test that: https://github.com/mrousavy/react-native-vision-camera/pull/1674#issuecomment-1684104217

If the issue cannot be reproduced with that version/PR anymore, then hoorayy, I fixed it! 🎉 Otherwise please let me know and I'll keep this issue open to keep track of it.

Thank you!

ChetanAlmelkar commented 1 year ago

If I used enableProguardInReleaseBuilds=true then app crashes when i open camera from react-native-vision-camera.

mrousavy commented 1 year ago

Does it work if you disable proguard?