Surile / react-native-sunmi-printer

商米内置打印机
MIT License
44 stars 28 forks source link

Sunmi V2S - attempt to invoke interface method on null object reference #10

Closed ryanmitchell closed 2 years ago

ryanmitchell commented 2 years ago

Thanks for this package - it looks great.

When I try to use it (through EAS build on Expo) I'm getting:

Attempt to invoke interface method 'void com.sunmi.peripheral.printer.SunmiPrinterService.printText' on a null object reference

Am I missing something? My code is pretty basic:

import SunmiPrinter from '@heasy/react-native-sunmi-printer';

SunmiPrinter.printerText('Hello hello hello');
Surile commented 2 years ago

I haven't used it in Expo, I can't answer it for you, it is recommended not to use Expo

ryanmitchell commented 2 years ago

Its not Expo specific - I'm using EAS build which is the same as using Android studio. Its just a different build system but it has complete parity.

Have you ever tried/tested the library on a V2S? What hardware are you using?

Surile commented 2 years ago
image

I see Sunmi development documentation and there is no v2

ryanmitchell commented 2 years ago

See: https://www.sunmi.com/en-US/v2s/

Surile commented 2 years ago

@ryanmitchell See the latest document, wait a moment, I will update

Surile commented 2 years ago

@ryanmitchell Please try it with v2

Surile commented 2 years ago

@ryanmitchell Is it ready to use, I'm going to close this.

ryanmitchell commented 2 years ago

Struggling to get a build as I cant target the branch - it needs to be a release

Surile commented 2 years ago

Struggling to get a build as I cant target the branch - it needs to be a release

👌

ryanmitchell commented 2 years ago

I just tested against 1.6.2 and the build now fails... is not allowed in the manifest element - see: https://developer.android.com/guide/topics/manifest/manifest-element

Should it maybe be <original-package> as per: https://android.googlesource.com/platform/frameworks/base/+/master/packages/PackageInstaller/AndroidManifest.xml#5

Surile commented 2 years ago

@ryanmitchell You try again.

ryanmitchell commented 2 years ago

@Surile thanks. Unfortunately I'm back to getting the null object reference error so the change doesn't seem to have worked. Do you have any other ideas?

Surile commented 2 years ago

@ryanmitchell

package android:name="woyou.aidlservice.jiuiv5"

You try to put that code in AndroidManifest.xml under Android project

ryanmitchell commented 2 years ago

Same error as before - AndroidManifest.xml:37: AAPT: error: <manifest> tag is missing 'package' attribute - this means <package> is not valid in AndroidManifest

Surile commented 2 years ago

I saw the Chinese document, the document said that v2 and v2plus need to add this

ryanmitchell commented 2 years ago

Can you send the link to the document so I can investigate?

Surile commented 2 years ago

Documentation

ryanmitchell commented 2 years ago

Thanks, I see now, it needs added to queries. I've got it working - I'll open a PR with the config needed for expo incase anyone else needs it.

ryanmitchell commented 2 years ago

Thank you!

Surile commented 2 years ago

Thanks, I see now, it needs added to queries. I've got it working - I'll open a PR with the config needed for expo incase anyone else needs it.

Ok, thank you

ryanmitchell commented 2 years ago

I think the best thing might be to add something to the docs:

For Expo users, you need to add a config plugin as follows:

const { withAndroidManifest } = require("@expo/config-plugins")

module.exports = function androiManifestPlugin(config) {
  return withAndroidManifest(config, async config => {
    let androidManifest = config.modResults.manifest

    androidManifest.queries.push({
        'package': {
            '$': {
                'android:name': 'woyou.aidlservice.jiuiv5'
            }
        }
    });

    return config
  })
}

Add this to a file called android-manifest.plugin.js in your app root, then add a reference to this file your expo.plugins array in app.json... eg.

        "plugins": [
            "./android-manifest.plugin.js"
        ]
daniel1up commented 1 year ago

Hello guys,

I see that you have solved this issue of V2s for EAS, but what about Android build? Is there any opportunity to make it work?

Thanks

Surile commented 1 year ago

Hello guys,

I see that you have solved this issue of V2s for EAS, but what about Android build? Is there any opportunity to make it work?

Thanks

it should be ok

daniel1up commented 1 year ago

Yes, it works now. Thanks

anastely commented 1 year ago

Hey @ryanmitchell we are trying to use this lib with Sunmi V2s

But got this error as @MnaveedS said

Can you please share with us your Gradle files and other stuff to make this works with V2s

https://github.com/Surile/react-native-sunmi-printer/issues/22

ryanmitchell commented 1 year ago

I use expo, so dont have grade files to share. My comment above shows how I set it up to work.

d-lindau commented 6 months ago

Im having the same issue. Tried multiple versions of React-native. V2s and not using EAS or Expo. Attempt to invoke interface method 'void com.sunmi.peripheral.printer.SunmiPrinterService.printText' on a null object reference