cordova-plugin-printer icon indicating copy to clipboard operation
cordova-plugin-printer copied to clipboard

Android 10 app getting crash

Open jd048 opened this issue 5 years ago • 8 comments

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[])' on a null object reference at de.appplant.cordova.plugin.printer.reflect.Meta.invokeMethod(Meta.java:87)

jd048 avatar Oct 23 '19 08:10 jd048

Hey, i was facing similar issue but i was finally able to resolve it. So i'm writing the steps i followed(targetting API level 28 as per Android's recent policy):

  1. In your config.xml, add: <preference name="android-minSdkVersion" value="19" /> <preference name="android-targetSdkVersion" value="28" />

  2. Minimum cordova-android version required for API Levels 19-28 is 8.X.X. (Important)

  3. Starting with Android 9 (API level 28), cleartext support is disabled by default. To resolve this in your config.xml add - <platform name="android"> ... <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application"> <application android:usesCleartextTraffic="true" /> </edit-config> .... </platform>

Also add:

xmlns:android="http://schemas.android.com/apk/res/android"

in your <widget tag at the top should look like this

<widget id="io.ionic.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">

Feel free to revert, if this doesn't solve your issue!

echosidd avatar Nov 01 '19 08:11 echosidd

i have same problem

JessicaMouta avatar Nov 26 '19 20:11 JessicaMouta

@echosidd I am facing this issue and I came across your comment.

I agree with everything you say but I can't find which has your comment to do with the issue we are talking. We are suffering this bug after upgrading targetsdk from 26 to 28, but then if you are suffering this bug after upgrading to minsdk 28 what? Adding clearTextTraffic has no relation with the printer.

Regards.

axelcostaspena avatar Nov 27 '19 15:11 axelcostaspena

Any update for this issue, its really very big issue for android 10.0

jd048 avatar Dec 02 '19 12:12 jd048

Same problem here

createdbyconnor avatar Dec 03 '19 17:12 createdbyconnor

In my case. I use $cordovaPrinter also crash when I call "$cordovaPrinter.print()" then I change to "cordova.plugins.printer.print()" it work fine.

jpaopisut avatar Dec 24 '19 03:12 jpaopisut

This issue can be fixed if you copy 2 packages ext and reflect from below URL. https://github.com/WeAreJoinly/Joinly-App/tree/master/platforms/android/src/de/appplant/cordova/plugin/printer paste these 2 folders inside your printer plugin android package.

anupbui avatar Mar 29 '20 11:03 anupbui

I can consistently replicate this issue in Android 10 for version 0.7.3. The issue is because the getPrintJob method does not exist as it will be indicated in the stacktrace in Log Cat. Offending code: https://github.com/katzer/cordova-plugin-printer/blob/0.7.3/src/android/ext/PrintManager.java#L226

The solution for me was to simply first check if the method variable is null before using it.

    private void notifyOnPrintJobStateChanged(PrintJobId printJobId) {
        if (listener != null && listener.get() != null) {
            Method method = Meta.getMethod(getInstance().getClass(),
                    "getPrintJob", PrintJobId.class);

            if (method != null) {

                PrintJob job = (PrintJob) Meta.invokeMethod(getInstance(),
                        method, printJobId);

                listener.get().onPrintJobStateChanged(job);
            }
        }
    }

joe-at-startupmedia avatar Apr 26 '20 20:04 joe-at-startupmedia