Surile / react-native-sunmi-printer

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

java.lang.NullPointerException: Attempt to invoke interface method 'void com.sunmi.peripheral.printer.SunmiPrinterService.lineWrap' on a null object reference on Sunmi V2s device #22

Closed MnaveedS closed 1 year ago

MnaveedS commented 1 year ago

Hi,

I am getting the following error when attempting to print on Sunmi V2s device,

java.lang.NullPointerException: Attempt to invoke interface method 'void com.sunmi.peripheral.printer.SunmiPrinterService.lineWrap(int, com.sunmi.peripheral.printer.InnerResultCallback)' on a null object reference

I am using the following, React: 16.13.1 React Native: 0.64.1 (CLI) @heasy/react-native-sunmi-printer: ^1.7.0 Sunmi V2s

BuildGradle buildToolsVersion = "30.0.2" minSdkVersion = 26 compileSdkVersion = 31 targetSdkVersion = 31 gradle-6.5-all classpath('com.android.tools.build:gradle:4.1.0')

I am able to Run the Print using the below configs but i need to be able to run with the above configs instead as i need to have SDK version 31

The following Gradle settings allow me to print buildToolsVersion = "29.0.3" minSdkVersion = 26 compileSdkVersion = 29 targetSdkVersion = 29 gradle-6.2-all classpath("com.android.tools.build:gradle:3.5.3");

Does this package work with compileSdkVersion = 31,targetSdkVersion = 31, Is there anything that can be done to make the print work with `SDK version 31.

Any help would be much appreciated. Thanks.

Surile commented 1 year ago

@MnaveedS I'm not doing this business now, I don't know, you can try compileSdkVersion = 31, targetSdkVersion = 31 to change it. However, I think it may be necessary to change the parameters of buildToolsVersion.

MnaveedS commented 1 year ago

@Surile Thanks for the reply i will attempt to modify the package locally, Any ideas on alternative packages available, that are currently maintained for Sunmi react Native

Surile commented 1 year ago

ok

anastely commented 1 year ago

hey @MnaveedS, did you solve it?

MnaveedS commented 1 year ago

@anastely No i've tried bumping all the gradle plugin versions and sdk versions up no solution yet. do you have any ideas?

anastely commented 1 year ago

@MnaveedS Sadly No, I guess we should bump the lib versions!

check the `android/build.Gradle file, can you try bumping it, and adding this

dependencies{ implementation 'com.sunmi:printerlibrary:1.0.18' }

I don't have Sunmi V2s, I have V2 and this lib works well here.

let me know. If it works, please 🙏

MnaveedS commented 1 year ago

@anastely i've done that too my build gradle file within the package `buildscript { if (project == rootProject) { repositories { google() jcenter() }

    dependencies {
      // classpath 'com.android.tools.build:gradle:3.5.3'
        classpath 'com.android.tools.build:gradle:4.1.0'
      }
    }
  }

apply plugin: 'com.android.library'

def safeExtGet(prop, fallback) {
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

android {
  compileSdkVersion 31
  buildToolsVersion '30.0.2'
  defaultConfig {
    minSdkVersion 19
    targetSdkVersion 31
    versionCode 1
    versionName "1.0"

  }

  buildTypes {
    release {
      minifyEnabled false
    }
  }
  lintOptions {
    disable 'GradleCompatible'
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

repositories {
  mavenLocal()
  maven {
    // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
    url("$rootDir/../../../../node_modules/react-native/android")
  }
  google()
  jcenter()
}

dependencies {
  //noinspection GradleDynamicVersion
  implementation "com.facebook.react:react-native:+"  // From node_modules
  // implementation "com.sunmi:printerlibrary:1.0.13"
  implementation 'com.sunmi:printerlibrary:1.0.18'

}

`

anastely commented 1 year ago

@MnaveedS check this

https://github.com/Surile/react-native-sunmi-printer/issues/10#issuecomment-1113055983

MnaveedS commented 1 year ago

@anastely I did see that and i checked the androidManifest it already had it <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.reactnativesunmiprinter"> <original-package android:name="woyou.aidlservice.jiuiv5"/> </manifest>

I further also tried adding it to my main application manifest too but it didn't work out.

anastely commented 1 year ago

Hey @MnaveedS I want to say it works here :D

try this

android/app/build.gradle

...
dependencies {
....
    implementation 'com.sunmi:printerlibrary:1.0.18'
}

android/app/src/main/AndroidManifest.xml


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.camp.myapp">
    <queries>
        <package android:name="woyou.aidlservice.jiuiv5" />
    </queries>
    <application>......</application>
</manifest>
MnaveedS commented 1 year ago

Hi @anastely Yes the above change fixed it and it works now thanks