mrousavy / react-native-vision-camera

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

🐛 App crashes on launch after obfuscated by Dexguard in Android #2318

Closed burakakyol closed 7 months ago

burakakyol commented 9 months ago

What's happening?

We're using vision-camera for scanning the barcode. We had no error while running on debug and release mode and the application worked as expected when the obfuscation was disabled. However, after obfuscating the application by using dexguard(enterprise proguard) , the application started to crash on splash screen. I couldn't find any keep rule in the documentation.

Before installing the library, there was no crash in the application.

Reproduceable Code

const device = useCameraDevice('back');

   device && (
            <View style={{ flex: 1 }}>
              <Camera
                testID="rncamera-view"
                fps={30}
                codeScanner={codeScanner}
                device={device}
                style={StyleSheet.absoluteFill}
                isActive={true}
              />
              <BarcodeMask
                outerMaskOpacity={0.5}
                lineAnimationDuration={1200}
                width={Dimensions.get('screen').width * 0.7}
                height={Dimensions.get('screen').height * 0.25}
              />
              {overlay && barCode === '' && (
                <CameraOverlay>
                  <Image
                    source={warningImage}
                    style={{ width: 40, height: 40, flexDirection: 'column', marginRight: 20 }}
                  />
                  <CameraOverlayText>{t('overlay')}</CameraOverlayText>
                </CameraOverlay>
              )}
            </View>

Relevant log output

2023-12-22 09:29:53.334 28312-28312 SoLoader                com.reactnativeproject.test           V  libjscexecutor.so not found on /data/data/com.reactnativeproject.test/lib-main
2023-12-22 09:29:53.334 28312-28312 SoLoader                com.reactnativeproject.test           V  libjscexecutor.so not found on /data/app/~~YWbcVz0p-0omcS7eIIwWqg==/com.reactnativeproject.test-Ypvl8TOzMBYvTEKDBqMl-Q==/lib/arm64
2023-12-22 09:29:53.334 28312-28312 SoLoader                com.reactnativeproject.test           V  libjscexecutor.so not found on /system/lib64
2023-12-22 09:29:53.334 28312-28312 SoLoader                com.reactnativeproject.test           V  libjscexecutor.so not found on /vendor/lib64
2023-12-22 09:29:53.336 28312-28312 SoLoader                com.reactnativeproject.test           E  couldn't find DSO to load: libjscexecutor.so
                                                                                                        SoSource 0: com.facebook.soloader.ApkSoSource[root = /data/data/com.reactnativeproject.test/lib-main flags = 1]
                                                                                                        SoSource 1: com.facebook.soloader.DirectorySoSource[root = /data/app/~~YWbcVz0p-0omcS7eIIwWqg==/com.reactnativeproject.test-Ypvl8TOzMBYvTEKDBqMl-Q==/lib/arm64 flags = 0]
                                                                                                        SoSource 2: com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2]
                                                                                                        SoSource 3: com.facebook.soloader.DirectorySoSource[root = /vendor/lib64 flags = 2]
                                                                                                        Native lib dir: /data/app/~~YWbcVz0p-0omcS7eIIwWqg==/com.reactnativeproject.test-Ypvl8TOzMBYvTEKDBqMl-Q==/lib/arm64
                                                                                                     result: 0
2023-12-22 09:29:53.338 28312-28312 SoLoader                com.reactnativeproject.test           V  libhermes.so not found on /data/data/com.reactnativeproject.test/lib-main
2023-12-22 09:29:53.338 28312-28312 SoLoader                com.reactnativeproject.test           D  libhermes.so found on /data/app/~~YWbcVz0p-0omcS7eIIwWqg==/com.reactnativeproject.test-Ypvl8TOzMBYvTEKDBqMl-Q==/lib/arm64
2023-12-22 09:29:53.338 28312-28312 SoLoader                com.reactnativeproject.test           D  Not resolving dependencies for libhermes.so
2023-12-22 09:29:53.387 28312-28312 SoLoader                com.reactnativeproject.test           V  libhermes_executor.so not found on /data/data/com.reactnativeproject.test/lib-main
2023-12-22 09:29:53.387 28312-28312 SoLoader                com.reactnativeproject.test           D  libhermes_executor.so found on /data/app/~~YWbcVz0p-0omcS7eIIwWqg==/com.reactnativeproject.test-Ypvl8TOzMBYvTEKDBqMl-Q==/lib/arm64
2023-12-22 09:29:53.387 28312-28312 SoLoader                com.reactnativeproject.test           D  Not resolving dependencies for libhermes_executor.so
2023-12-22 09:29:53.790 28312-30992 SoLoader                com.reactnativeproject.test           V  libfbjni.so not found on /data/data/com.reactnativeproject.test/lib-main
2023-12-22 09:29:53.790 28312-30992 SoLoader                com.reactnativeproject.test           V  libfbjni.so not found on /data/app/~~YWbcVz0p-0omcS7eIIwWqg==/com.reactnativeproject.test-Ypvl8TOzMBYvTEKDBqMl-Q==/lib/arm64
2023-12-22 09:29:53.791 28312-30992 SoLoader                com.reactnativeproject.test           V  libfbjni.so not found on /system/lib64
2023-12-22 09:29:53.791 28312-30992 SoLoader                com.reactnativeproject.test           V  libfbjni.so not found on /vendor/lib64
2023-12-22 09:29:53.793 28312-30992 SoLoader                com.reactnativeproject.test           E  couldn't find DSO to load: libfbjni.so
                                                                                                        SoSource 0: com.facebook.soloader.ApkSoSource[root = /data/data/com.reactnativeproject.test/lib-main flags = 1]
                                                                                                        SoSource 1: com.facebook.soloader.DirectorySoSource[root = /data/app/~~YWbcVz0p-0omcS7eIIwWqg==/com.reactnativeproject.test-Ypvl8TOzMBYvTEKDBqMl-Q==/lib/arm64 flags = 0]
                                                                                                        SoSource 2: com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2]
                                                                                                        SoSource 3: com.facebook.soloader.DirectorySoSource[root = /vendor/lib64 flags = 2]
                                                                                                        Native lib dir: /data/app/~~YWbcVz0p-0omcS7eIIwWqg==/com.reactnativeproject.test-Ypvl8TOzMBYvTEKDBqMl-Q==/lib/arm64
                                                                                                     result: 0
2023-12-22 09:29:53.796 28312-30992 AndroidRuntime          com.reactnativeproject.test           E  FATAL EXCEPTION: create_react_context
                                                                                                    Process: com.reactnativeproject.test, PID: 28312
                                                                                                    java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libfbjni.so
                                                                                                        SoSource 0: com.facebook.soloader.ApkSoSource[root = /data/data/com.reactnativeproject.test/lib-main flags = 1]
                                                                                                        SoSource 1: com.facebook.soloader.DirectorySoSource[root = /data/app/~~YWbcVz0p-0omcS7eIIwWqg==/com.reactnativeproject.test-Ypvl8TOzMBYvTEKDBqMl-Q==/lib/arm64 flags = 0]
                                                                                                        SoSource 2: com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2]
                                                                                                        SoSource 3: com.facebook.soloader.DirectorySoSource[root = /vendor/lib64 flags = 2]
                                                                                                        Native lib dir: /data/app/~~YWbcVz0p-0omcS7eIIwWqg==/com.reactnativeproject.test-Ypvl8TOzMBYvTEKDBqMl-Q==/lib/arm64
                                                                                                     result: 0
                                                                                                        at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(Unknown Source:270)
                                                                                                        at com.facebook.soloader.SoLoader.loadLibraryBySoNameImpl(Unknown Source:124)
                                                                                                        at com.facebook.soloader.SoLoader.loadLibraryBySoName(Unknown Source:2)
                                                                                                        at com.facebook.soloader.SoLoader.loadLibrary(Unknown Source:42)
                                                                                                        at com.facebook.soloader.NativeLoaderToSoLoaderDelegate.loadLibrary(Unknown Source:10)
                                                                                                        at com.facebook.soloader.nativeloader.NativeLoader.loadLibrary(Unknown Source:8)
                                                                                                        at com.facebook.soloader.nativeloader.NativeLoader.loadLibrary(Unknown Source:1)
                                                                                                        at com.facebook.jni.HybridData.<clinit>(Unknown Source:2)
                                                                                                        at com.facebook.hermes.reactexecutor.HermesExecutor.initHybridDefaultConfig(Native Method)
                                                                                                        at com.facebook.hermes.reactexecutor.HermesExecutor.<init>(Unknown Source:2)
                                                                                                        at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(Unknown Source:8)
                                                                                                        at com.facebook.react.ReactInstanceManager$5.run(Unknown Source:59)
                                                                                                        at java.lang.Thread.run(Thread.java:923)

Camera Device

{
  "formats": null,
  "sensorOrientation": "landscape-right",
  "hardwareLevel": "limited",
  "maxZoom": 4,
  "minZoom": 1,
  "maxExposure": 200,
  "supportsLowLightBoost": false,
  "neutralZoom": 1,
  "physicalDevices": [
    "wide-angle-camera"
  ],
  "supportsFocus": true,
  "supportsRawCapture": false,
  "isMultiCam": false,
  "minExposure": -200,
  "name": "BACK (0)",
  "hasFlash": true,
  "hasTorch": true,
  "position": "back",
  "id": "0"
}

Device

Redmi Note 11 ( Android 11), Galaxy A32 ( Android 11)

VisionCamera Version

3.6.13

Can you reproduce this issue in the VisionCamera Example app?

No, I cannot reproduce the issue in the Example app

Additional information

mrousavy commented 9 months ago

Hey - sorry I don't really think this is related to VisionCamera.

Maybe try removing this line: https://github.com/mrousavy/react-native-vision-camera/blob/7905f2c057869698a4f5afa3182bec4cd2a5fe58/package/android/build.gradle#L145

mrousavy commented 8 months ago

Hey - did you try to remove this line? If yes, did it work?

burakakyol commented 8 months ago

Hi @mrousavy I'm sorry for not getting back to you sooner.

We removed the line you mentioned, but it didn't work. I'll get back to you tomorrow with the details.

Thank you.

mrousavy commented 8 months ago

Okay thanks - let me know because this is weird haven't seen this before

burakakyol commented 8 months ago

Hi @mrousavy

I removed the line you mentioned. However, I got a different crash from the application.

 couldn't find DSO to load: libjscexecutor.so
                                                                                                        SoSource 0: com.facebook.soloader.ApkSoSource[root = /data/data/tr.sisal.streetvendor.test/lib-main flags = 1]
                                                                                                        SoSource 1: com.facebook.soloader.DirectorySoSource[root = /data/app/~~jU4dZ_nfHW8CmZVGk6dvLA==/tr.sisal.streetvendor.test-OPAHM0LywtyiQJVkT_Q7UQ==/lib/arm64 flags = 0]
                                                                                                        SoSource 2: com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2]
                                                                                                        SoSource 3: com.facebook.soloader.DirectorySoSource[root = /vendor/lib64 flags = 2]
                                                                                                        Native lib dir: /data/app/~~jU4dZ_nfHW8CmZVGk6dvLA==/tr.sisal.streetvendor.test-OPAHM0LywtyiQJVkT_Q7UQ==/lib/arm64
                                                                                                     result: 0

libjscexecutor.so is also different .so file that is placed in the gradle file of the library. Should I remove it ?

OmmAshutosh commented 8 months ago

1) first install this in your device npm install @react-native-camera/core @react-native-camera/barcode 2)make sure you have linked the packages correctly. If you are using React Native 0.60 or above, auto-linking should work. 3)try this code according to your preferences;

import React, { useEffect, useState } from 'react'; import { StyleSheet, View, Dimensions, Image } from 'react-native'; import Camera from '@react-native-camera/core'; import BarcodeMask from '@react-native-camera/barcode-mask'; import { useCameraDevice } from '@react-native-camera/core';

const CameraScreen = () => { const device = useCameraDevice('back'); const [barCode, setBarCode] = useState('');

const handleBarCodeRead = (e) => { setBarCode(e.data); };

useEffect(() => { if (barCode !== '') { // Your code here, for example: // navigate to a new screen and pass the barCode value } }, [barCode]);

return (

{device && ( )} {barCode && ( Barcode Scanned: {barCode} )}

); };

const styles = StyleSheet.create({ container: { flex: 1, }, overlay: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: 'rgba(0, 0, 0, 0.5)', justifyContent: 'center', alignItems: 'center', }, warningImage: { width: 40, height: 40, }, warningText: { color: 'white', fontSize: 16, marginTop: 20, }, });

export default CameraScreen;

mrousavy commented 7 months ago

Hey - sorry but I read the crash logs again and there is nothing related to VisionCamera. You can try uninstalling VisionCamera and probably get the same error.

This is due to something stripping away native libraries (probably ProGuard)

burakakyol commented 6 months ago

We solved the issue by applying the dexguard rules below:

-keepresourcefiles lib/**/libfb*.so,lib/**/libreact*.so,lib/**/libyoga*.so,lib/**/libhermes.so,lib/**/libhermes_executor.so,lib/**/libjsi*.so,*/lib/**/libfb*.so,*/lib/**/libreact*.so,*/lib/**/libyoga*.so,*/lib/**/libhermes.so,*/lib/**/libhermes_executor.so,*/lib/**/libjsi*.so