katzer / cordova-plugin-printer

Print HTML documents
Apache License 2.0
312 stars 291 forks source link

Android 10 app getting crash #233

Open jd048 opened 5 years ago

jd048 commented 5 years ago

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)

echosidd commented 4 years ago

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!

JessicaMouta commented 4 years ago

i have same problem

axelcostaspena commented 4 years ago

@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.

jd048 commented 4 years ago

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

createdbyconnor commented 4 years ago

Same problem here

jpaopisut commented 4 years ago

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

anupbui commented 4 years ago

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.

joe-at-startupmedia commented 4 years ago

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);
            }
        }
    }