Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After upgrading to version 1.0.0 package stopped working on Android #115

Open
aliravn opened this issue Mar 26, 2024 · 11 comments
Open

After upgrading to version 1.0.0 package stopped working on Android #115

aliravn opened this issue Mar 26, 2024 · 11 comments

Comments

@aliravn
Copy link

aliravn commented Mar 26, 2024

Hi,
I have upgraded the package to version 1.0.0, but after doing so it stopped working on my Android device. First, after the package update the App completely crashed with this error so I had to fix that. Then after taking a picture and confirming it just returns to the screen before the scanner has started. DocumentScanner.scanDocument() doesn't return anything - no scannedImages, no status, no error - nothing. It doesn't even get to the second log. On iOS however it works as it used to without any noticeable issues.

Code:
image

App:
"react-native": "0.64.4",
"react-native-document-scanner-plugin": "1.0.0",

Devices:
Samsung A41 Android 12
Samsung A52s Android 14

I don't have much experience with RN development so I am a bit puzzled what I may be doing wrong.
Initially the package worked just fine out-of-the-box. Thanks in advance for your insights!

@dmarcs
Copy link
Contributor

dmarcs commented Mar 26, 2024

Any errors when you run adb logcat?

@konri
Copy link

konri commented Mar 26, 2024

Hey, I had the same problem, camera didn't want to open and not have any logs from logcat.

I figure out that before using the camera you need to ask for permission so before your code do:


async function requestCameraPermission() {
  try {
    return PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA);
  } catch (err) {
     console.error(err);
  }
}

and in method scanDocument you need to put:


 if (Platform.OS === 'android') {
    await requestCameraPermission();
  }
  return DocumentScanner.scanDocument()

And it's working fine with me.

I've tested on phisical device.

@aliravn
Copy link
Author

aliravn commented Mar 27, 2024

Any errors when you run adb logcat?

@dmarcs I have tried to filter only the warnings and errors during the time I was starting the camera and confirming the taken image, but it is still way too many and tbh, I have no idea which ones are relevant to my problem. Here is what I've got

rn-document-scanner-update-error-log.pdf

@aliravn
Copy link
Author

aliravn commented Mar 27, 2024

Hey, I had the same problem, camera didn't want to open and not have any logs from logcat.

I figure out that before using the camera you need to ask for permission so before your code do:

Hey @konri, I didn't have any problem with opening the camera. I could get to the point of adjusting the scan lines and securing the picture, but the was no file path returned. I have tried your code but it didn't change anything. Thanks nonetheless!

@dmarcs
Copy link
Contributor

dmarcs commented Mar 27, 2024

Thanks for sharing how you fixed it @konri, but you shouldn't need to ask for camera permissions. It's possible that you're using another plugin that requires camera permissions. This plugin by itself doesn't require camera permissions.

@aliravn can you please try to create a new React Native project, only install this plugin, and run your code?

@aliravn
Copy link
Author

aliravn commented Mar 28, 2024

@dmarcs I have created a fresh RN 64 project with nothing but document scanner plugin and the button that starts it
npx react-native@0.64.4 init projectname --version 0.64.4
npm i react-native-document-scanner-plugin
image
open android/gradle.properties and add org.gradle.jvmargs=-Xmx2048m
rebuild and start the project
running on physical device Android 14

The result is the same as described above, no errors in the console, no file path.
Here is the logcat log filtered with errors only 2024-03-28-rn-docu-scanner-error.pdf

@dmarcs
Copy link
Contributor

dmarcs commented Mar 29, 2024

Since your code stops, and doesn't run what's in the catch block I would expect to see a crash in your error logs. I don't see that though. I would recommend switching back to version 0.9.1 of this plugin for now since the only difference between that version and 1.0.0 is that I switched the Android document scanner from the one I created to Android's document scanner.

@mendrixsebas
Copy link

mendrixsebas commented Apr 9, 2024

New version works fine on a Samsung A53 with Android 14.
On an ancient Samsung S5 with Android 6.0.1, when the shutter button is pressed, it will show a toast stating that an unexpected error occurred and should try again later. Not long after that an alert will pop up with "Google Play-services has stopped".
Logcat shows an out of memory error:

2024-04-10 00:18:31.495 12131-12131 art                      I  Starting a blocking GC Alloc
2024-04-10 00:18:31.495 12131-12131 art                      I  Starting a blocking GC Alloc
2024-04-10 00:18:31.505 12131-12131 art                      I  Alloc sticky concurrent mark sweep GC freed 718(22KB) AllocSpace objects, 0(0B) LOS objects, 14% free, 93MB/109MB, paused 1.088ms total 10.273ms
2024-04-10 00:18:31.505 12131-12131 art                      I  Starting a blocking GC Alloc
2024-04-10 00:18:31.545 12131-12131 art                      I  Alloc partial concurrent mark sweep GC freed 229(8KB) AllocSpace objects, 1(7MB) LOS objects, 15% free, 85MB/101MB, paused 1.232ms total 38.060ms
2024-04-10 00:18:31.545 12131-12131 art                      I  Starting a blocking GC Alloc
2024-04-10 00:18:31.585 12131-12131 art                      I  Alloc concurrent mark sweep GC freed 7(224B) AllocSpace objects, 0(0B) LOS objects, 15% free, 85MB/101MB, paused 1.132ms total 40.077ms
2024-04-10 00:18:31.585 12131-12131 art                      I  Forcing collection of SoftReferences for 60MB allocation
2024-04-10 00:18:31.585 12131-12131 art                      I  Starting a blocking GC Alloc
2024-04-10 00:18:31.625 12131-12131 art                      I  Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 15% free, 85MB/101MB, paused 1.125ms total 39.390ms
2024-04-10 00:18:31.625 12131-12131 art                      W  Throwing OutOfMemoryError "Failed to allocate a 63701004 byte allocation with 16777216 free bytes and 42MB until OOM"
2024-04-10 00:18:31.635 12131-12131 art                      I  Starting a blocking GC Alloc
2024-04-10 00:18:31.635 12131-12131 art                      I  Starting a blocking GC Alloc
2024-04-10 00:18:31.645 12131-12131 art                      I  Alloc sticky concurrent mark sweep GC freed 3(448B) AllocSpace objects, 0(0B) LOS objects, 15% free, 85MB/101MB, paused 1.569ms total 9.269ms
2024-04-10 00:18:31.645 12131-12131 art                      I  Starting a blocking GC Alloc
2024-04-10 00:18:31.695 12131-12131 art                      I  Alloc partial concurrent mark sweep GC freed 6(192B) AllocSpace objects, 0(0B) LOS objects, 15% free, 85MB/101MB, paused 1.447ms total 55.253ms
2024-04-10 00:18:31.695 12131-12131 art                      I  Starting a blocking GC Alloc
2024-04-10 00:18:31.745 12131-12131 art                      I  Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 15% free, 85MB/101MB, paused 1.145ms total 43.191ms
2024-04-10 00:18:31.745 12131-12131 art                      I  Forcing collection of SoftReferences for 60MB allocation
2024-04-10 00:18:31.745 12131-12131 art                      I  Starting a blocking GC Alloc
2024-04-10 00:18:31.785 12131-12131 art                      I  Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 15% free, 85MB/101MB, paused 1.146ms total 39.259ms
2024-04-10 00:18:31.785 12131-12131 art                      W  Throwing OutOfMemoryError "Failed to allocate a 63701004 byte allocation with 16776320 free bytes and 42MB until OOM"
2024-04-10 00:18:31.815 12131-12131 CameraVFViewModel        W  Error occurred in exception handler [CONTEXT service_id=362 ]
                                                                java.lang.OutOfMemoryError: Failed to allocate a 63701004 byte allocation with 16776320 free bytes and 42MB until OOM
                                                                	at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                                	at android.graphics.Bitmap.nativeCreate(Native Method)
                                                                	at android.graphics.Bitmap.createBitmap(Bitmap.java:975)
                                                                	at android.graphics.Bitmap.createBitmap(Bitmap.java:946)
                                                                	at android.graphics.Bitmap.createBitmap(Bitmap.java:877)
                                                                	at m.gmg.c(:com.google.android.gms.optional_mlkit_docscan_ui@234914004@23.49.14 (020300-0):166)
                                                                	at com.google.android.gms.mlkit.docscan.ui.viewfinder.CameraViewFinderViewModel.b(:com.google.android.gms.optional_mlkit_docscan_ui@234914004@23.49.14 (020300-0):78)
                                                                	at m.guh.b(:com.google.android.gms.optional_mlkit_docscan_ui@234914004@23.49.14 (020300-0):20)
                                                                	at m.miv.e(:com.google.android.gms.optional_mlkit_docscan_ui@234914004@23.49.14 (020300-0):14)
                                                                	at m.mrt.a(:com.google.android.gms.optional_mlkit_docscan_ui@234914004@23.49.14 (020300-0):123)
                                                                	at m.mtf.b(:com.google.android.gms.optional_mlkit_docscan_ui@234914004@23.49.14 (020300-0):11)
                                                                	at m.mnm.a(Unknown Source)
                                                                	at m.gtz.a(:com.google.android.gms.optional_mlkit_docscan_ui@234914004@23.49.14 (020300-0):386)
                                                                	at m.ccu.b(:com.google.android.gms.optional_mlkit_docscan_ui@234914004@23.49.14 (020300-0):29)
                                                                	at m.ccu.d(:com.google.android.gms.optional_mlkit_docscan_ui@234914004@23.49.14 (020300-0):42)
                                                                	at m.ccx.j(:com.google.android.gms.optional_mlkit_docscan_ui@234914004@23.49.14 (020300-0):15)
                                                                	at m.ccq.run(:com.google.android.gms.optional_mlkit_docscan_ui@234914004@23.49.14 (020300-0):19)
                                                                	at android.os.Handler.handleCallback(Handler.java:739)
                                                                	at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                	at android.os.Looper.loop(Looper.java:158)
                                                                	at android.app.ActivityThread.main(ActivityThread.java:7230)
                                                                	at java.lang.reflect.Method.invoke(Native Method)
                                                                	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
2024-04-10 00:18:31.815 12131-12131 Choreographer            I  Skipped 62 frames!  The application may be doing too much work on its main thread.

@dVlad00
Copy link

dVlad00 commented Apr 11, 2024

I confirm that after upgrade from 0.9.1 -> 1.0.0 just stoped working on android. Working just fine on iOS. I tried knori fixing but wasn't doing much. I also try to implement like was implemented in docs but no change.

So what is happening in my app after I give permission for camera the app is trying to open camera. For a second a grey screen is appearing and after that a white screen with a puzzle logo with google play colors on top and with this text " Something went wrong please try again later " and there is a button with cancel that is taking me back to app. I can't trace any errors, or anything else. React-Native doesn't throw any error neither js.

Tested on Samsung galaxy A21s with android 12
Project has react-native 0.72.4

@sanduluca
Copy link

Tested on different phone models:

  1. Google Pixel 4a (android 13, play services 24.15.14) - every thing works ok
  2. Meizu M2 Note (android 7.1.2, play services 22.24.13) - scan fails with error Feature not available in the current version of the Google Play services.
    2.1. After manually updating the play service to version 24.13.x, i tried to open the document scanner. I got prompted to download some updates*. After the download completed the google document camera scanner opened
  3. Samsung A3 2017 (SM-A320F) (android 8, play services 23.44.14) - i tried to open the document scanner. I got prompted to download some updates*. After the download completed the google document camera scanner opened

*Document scanner with ML Kit on Android - Users might have to wait for the models, logic and UI flow to download before first use.

This are the only devices I have

Code I used:

import DocumentScanner from 'react-native-document-scanner-plugin';
import { request, PERMISSIONS } from 'react-native-permissions';

onPress={() => {
  return requestCameraPermission().then(status => {
    if (status !== 'granted') {
      console.log('Permission not granted')
      return;
    }

    DocumentScanner.scanDocument({
      maxNumDocuments: 1
    })
      .then(({ scannedImages = [] }) => {
        console.log(scannedImages);
        if (scannedImages.length > 0) {
          // set the img src, so we can view the first scanned image
          console.log(scannedImages[0]);
        }
      })
      .catch(e => {
        Alert.alert('Error on scan', e.message);
      });
  });
}}

export const requestCameraPermission = () => {
	if (Platform.OS === 'android') return request(PERMISSIONS.ANDROID.CAMERA);
	if (Platform.OS === 'ios') return request(PERMISSIONS.IOS.CAMERA);
	return Promise.reject('blocked');
};
// package.json
{
"react-native-document-scanner-plugin": "^1.0.0",
"react-native": "0.72.4",
"react-native-permissions": "^4.1.0",
}

@aliravn
Copy link
Author

aliravn commented May 7, 2024

After I have upgraded my project to RN 72.14 and tried again upgrading the package to 1.0.0 Android worked again. However, what I find somehow annoying with the new appearance of the Scan Camera there is an "Auto Capture" option selected by default and it manages to snap a pic even before the user pointed to a document they want to scan or figures out to press "Manual". Is there an option to set this to "Manual" by default or does it depend on some phone settings?
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants