Open aliravn opened 5 months ago
Any errors when you run adb logcat
?
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.
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
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!
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?
@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
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
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.
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.
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
Tested on different phone models:
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*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",
}
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?
Do you have any plans or is there a chance to still support the method you where using on 0.9.1? I'm working with devices that are remotely managed and lock down, users can't make manual updates of anything, including google play services, for this v1.0 is not working for us but 0.9.1 is perfect.
Maybe have a prop on the component or as a fallback? you have a great tool here and it would be perfect for what I need but I get a little anxious knowing I'll have to stick with an older version, specially if you say it will only support v1.0 method moving forward
BTW thanks for this is amazing
I would use 0.9.1 for your app. I'd rather keep things simple, and not support it moving forward.
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:
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!