ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
11.55k stars 983 forks source link

bug: Camera wont update reliably, only when the screen is touched/finger is dragged across the screen #6648

Open MadJaxon opened 1 year ago

MadJaxon commented 1 year ago

Im running into the same problem described here: https://forum.ionicframework.com/t/camera-issue-in-our-app-webview-or-cap-plugin/232843 (and couldnt find an issue here) but havent been able to get a working build for >10 days.

Capacitor Version

Capacitor Doctor

Latest Dependencies:

@capacitor/cli: 5.0.5 @capacitor/core: 5.0.5 @capacitor/android: 5.0.5 @capacitor/ios: 5.0.5

Installed Dependencies:

@capacitor/ios: not installed @capacitor/cli: 5.0.5 @capacitor/core: 5.0.5 @capacitor/android: 5.0.5

[error] Missing attribute in app/src/main

Platform(s)

Android (built on Win10)

Current Behavior

(According to the other post, this is only an issue with the webviewApi, which apparently the lib i need is using) On only <1/40 builds the camera is working and not freezing instantly and then only updating a single frame every couple of seconds. When i touch the screen the camera updates, but only fluid & reliable while i keep my finger moving across the screen. I had a single build that worked (was my 2nd or 3rd attempt), already tried to delete all the caches and/or the complete android project in various constellations. When trying to reproduce the issue as described below, i had to do a lot of builds until it failed (even had a single successfull build after porting all my code into the plain app, so that shouldnt be the problem). Maybe it is in some way related to the projects size? My Angular project itself has a rough built size of ~3.9MB (only an 512x512 logo, otherwise text/code)

Expected Behavior

The Camera should be able to deliver a (at least mostly) stutterless/constant stream of frames.

Code Reproduction // using @zxing/* was the quickest way for me to reproduce the original situation

ng new test && cd test npm i @zxing/browser@latest --save npm i @zxing/library@latest --save When running angular 15.x: npm i @zxing/ngx-scanner@3.9.0 --save When running angular 16.x: npm i @zxing/ngx-scanner@latest --save

npm i @capacitor/core @capacitor/android @capacitor/camera npm i -D @capacitor/cli add 'ZXingScannerModule' to the imports in app/app.module.ts change the app.component.html content to: <zxing-scanner></zxing-scanner> npx cap init --web-dir dist/test test com.test.app npx cap add android ng build npx cap sync npx cap open android add the following 2 lines to app/manifests/AndroidManifest.xml ( i've put them right after the opening tag) <uses-feature android:name="android.hardware.camera" android:required="true" /> <uses-permission android:name="android.permission.CAMERA" /> Both ways might fail with the same behaviour: Build APK, copy to device, install Deploy&start the app via Android Studio to/on my device via USB

My recreation of this yielded mostly in good builds, rarely a broken one. Could only get a broken build after i added a bunch of lorem ipsum text a couple of times to the app.component.html and deployed it each time.

Other Technical Details

Win10 Android Studio Flamingo | 2022.2.1 Patch 2 (built on May 12 2023) plugin: @capacitor/camera npm --version output: 9.5.1

node --version output: 18.16.0

Additional Context

other people with the same problem: https://forum.ionicframework.com/t/camera-issue-in-our-app-webview-or-cap-plugin/232843

MadJaxon commented 1 year ago

While just running ./gradlew build instead of building via the gui i got 4 working builds in a row... so for me this can (hopefully) be tabled as a non-issue as well. im available for further troubleshooting if wanted/needed

mark-hipecommerce commented 1 year ago

We had the same exact problem and followed the advice here: https://github.com/mebjas/html5-qrcode/issues/779

Which was to "Add a small animation on site(Add invisible block with infinite rotate animation) and bug will be fixed" which, to our surprise, did indeed resolve this issue for us.

MadJaxon commented 1 year ago

Thanks for the info, will try this if i should run into it again, as said building it via cli fixed the issue for me as well