bthurlow / nativescript-imagecropper

A nativescript image cropping plugin.
Other
49 stars 35 forks source link

Crashes on Android 4.4 #66

Closed Mafick closed 4 years ago

Mafick commented 4 years ago

Which platform(s) does your issue occur on?

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.

Hello, I try to take a picture, crop it and than upload it. Unfortunately by the crop step my app crashes on this device. On newer devices it works perfectly. Here is the stack trace from the Google preview report

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2596)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2653)
  at android.app.ActivityThread.access$800 (ActivityThread.java:156)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1355)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:157)
  at android.app.ActivityThread.main (ActivityThread.java:5872)
  at java.lang.reflect.Method.invokeNative (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:858)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:674)
  at dalvik.system.NativeStart.main (Native Method)
Caused by: android.content.res.Resources$NotFoundException: 
  at android.content.res.Resources.loadDrawable (Resources.java:2134)
  at android.content.res.Resources.getDrawable (Resources.java:711)
  at androidx.core.content.ContextCompat.getDrawable (ContextCompat.java:465)
  at com.yalantis.ucrop.UCropActivity.setupAppBar (UCropActivity.java:345)
  at com.yalantis.ucrop.UCropActivity.setupViews (UCropActivity.java:296)
  at com.yalantis.ucrop.UCropActivity.onCreate (UCropActivity.java:125)
  at android.app.Activity.performCreate (Activity.java:5312)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1111)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2552)
Caused by: org.xmlpull.v1.XmlPullParserException: 
  at android.graphics.drawable.Drawable.createFromXmlInner (Drawable.java:933)
  at android.graphics.drawable.Drawable.createFromXml (Drawable.java:877)
  at android.content.res.Resources.loadDrawable (Resources.java:2130)

Is there any code involved?

home.component.ts

public onTakePicture() {
        requestPermissions().then(
            () => {
                takePicture({width: 150, height: 150, keepAspectRatio: true, saveToGallery: false, allowsEditing: false, cameraFacing: 'front'})
                    .then(imageAsset => {
                            ImageSource.fromAsset(imageAsset)
                                .then((imageSource: ImageSource) => {

                                    this.imageService.cropImage(imageSource)
                                        .then(croppedImage => {

                                                const filePath = this.saveFile(croppedImage);
                                                this.imageService.uploadUserImage(filePath);
                                                this.userImage = {headers: {Authorization: ''}, method: '', url: ''};
                                                this.isLoading = true;
                                                setTimeout(() => {
                                                    this.userImage = this.imageService.getCurrentUserImageSrc();
                                                    this.isLoading = false;
                                                }, 3000);

                                            }
                                        ).catch(function (e) {
                                        console.log(e);
                                    });
                                }, (error) => {
                                    console.log('Error: ' + error);
                                });
                        },
                        () => alert('permissions rejected')
                    );
            });
    }

image.service.ts

public cropImage(imageSource: ImageSource): Promise<ImageSource> {
        return new Promise<ImageSource>((resolve, reject) => {
            const imageCropper = new ImageCropper();
            imageCropper.show(imageSource, {width: 800, height: 800})
                .then((args) => {
                    let croppedImage = args.image;
                    resolve(croppedImage);
                })
                .catch(function (e) {
                    console.log(e);
                    reject(null);
                });
        });
    }
shiv19 commented 4 years ago

@mailiam minimum api level for the latest version of this plugin is 21

Older version (1.x) of this plugin did support API 19, but that version doesn't work with {N} 6, You might want to try other android cropping libs and conditionally use that in case of API 19

Mafick commented 4 years ago

You might want to try other android cropping libs and conditionally use that in case of API 19

Can you provide another one here? I only found this one.

shiv19 commented 4 years ago

Look for it on Android arsenal

Mafick commented 4 years ago

... not very helpful ... I also need this feature for ios, so make it sense to use another android lib here?

shiv19 commented 4 years ago

You can use this cropper for ios and android. Except for android api level below 21

What I'm asking you to do is to look for a android cropping lib on Android arsenal that you can use in android api level 20 and below.

Mafick commented 4 years ago

And how I handle than my ios use cases?

shiv19 commented 4 years ago

This plugin will handle ios and android for you. I'm asking you to use a different lib conditionally just for android api 19.