NativeScript / nativescript-camera

NativeScript plugin to empower using device camera.
Apache License 2.0
93 stars 47 forks source link

App crashes when saving photo on Android 10 devices #245

Closed jakubgondar closed 4 years ago

jakubgondar commented 4 years ago

Which platform(s) does your issue occur on?

Android 10 (Android 9 and lower seems to work fine), devices that I have tested this issue:

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

Nativescript-camera plugin does not work on Android 10 devices, our clients were complaining mostly about Samsung Galaxy and Xiaomi MI devices. It does not work also on Android 10.

Is there any code involved?

I am attaching simple demo app that is supposed to just take photo and show it in Angular component. App was generated via command tns create as Angular Hello world app. tns650.zip

To reproduce issue: 1) unpack ZIP 2) run npm ci (installs exact vesions from package-lock.json 3) run tns platform clean android 4) run tns debug android 5) Click "Click here to take photo", allow permissions and take photo. After taking photo, photo should appear below the button on screen.

On Android 10 emulator, it throws error JS: Error: cancelled in the console. On Samsung Galaxy M20, application crashes. See attached GIF video how it behaves on real device: ezgif com-resize

Error stack: tns650error.txt

Workaround

I have found out that when targetSdkVersion is set to 28 (not default 29 in TNS 6.5.0) then application works :

...
android {
    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 28
...
aschurf commented 4 years ago

I get a similar error in Xiaomi Mi9se on Android 10 QKQ, after the photo the application closes

octo888 commented 4 years ago

Same on Pixel 3a and Samsung S20 (both android 10)

Geotracer commented 4 years ago

I have the same issue with my recent app. Even with the same type of phone, the app crashes when confirming the photo. Mostly after the first install, the app crashes. The other times it crashes randomly.

akshaysisodia commented 4 years ago

I also have the same issue in my redmi k20 image didn't appears and in console it shows JS: Error: cancelled.

NathanaelA commented 4 years ago

You need to add the following key android:requestLegacyExternalStorage="true" if you are targetting API 29 or higher and you want to use the normal file api.

<manifest ... >
<!-- This attribute is "false" by default on apps targeting
     Android 10 or higher. -->
  <application android:requestLegacyExternalStorage="true" ... >
    ...
  </application>
</manifest>
jakubgondar commented 4 years ago

@NathanaelA thanks for response, but would you mind at least adding this note to the plugin home page README.md? TNS 6.5.0 has default target API 29 so apps built with this plugin will by default crash on Android 10.

akshaysisodia commented 4 years ago

@NathanaelA Thank You So much it worked

BMwanza commented 3 years ago

@NathanaelA's solution did not work for me.

My target API is set to 29, as it is now required by the Play Store, but I cannot get it work. App crashes when trying to take a picture