Surile / react-native-sunmi-printer

商米内置打印机
MIT License
47 stars 33 forks source link

Error on ContextCompat.registerReceiver #52

Open matheusbento opened 3 months ago

matheusbento commented 3 months ago

Hey Guys, I'm having the following issue when trying to run yarn Android.

I was using another lib was working, but there was an issue related to slow printing: https://github.com/suraneti/react-native-sunmi-v2-printer

But I installed this one and is having this issue.

Can anyone help?

"react-native": "0.68.2", "@heasy/react-native-sunmi-printer": "^1.8.3",

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Warning: elemento inesperado (uri:"", local:"extension-level"). Os elementos esperados são <{}codename>,<{}layoutlib>,<{}api-level>
Warning: elemento inesperado (uri:"", local:"base-extension"). Os elementos esperados são <{}codename>,<{}layoutlib>,<{}api-level>
../node_modules/@heasy/react-native-sunmi-printer/android/src/main/java/com/reactnativesunmiprinter/SunmiScanModule.java:99: error: cannot find symbol
    ContextCompat.registerReceiver(reactContext, receiver, filter, Context.RECEIVER_EXPORTED);
                 ^
  symbol:   method registerReceiver(ReactApplicationContext,BroadcastReceiver,IntentFilter,int)
  location: class ContextCompat
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: ../node_modules/@heasy/react-native-sunmi-printer/android/src/main/java/com/reactnativesunmiprinter/SunmiScanModule.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

FAILURE: Build failed with an exception.
Arekku04 commented 2 months ago

I encountered this error too. This issue comes from #48. What I did was I just removed that implementation and it worked just fine. To know more about what it does, I suggest to check the mentioned item.

image

matheusbento commented 2 months ago

The weird thing is that I'm with the same code you mentioned @Arekku04

image
Arekku04 commented 2 months ago

The weird thing is that I'm with the same code you mentioned @Arekku04

image

Have you tried deleting that line of code?

Hello @alexsegura was wondering what could be the reason for this since you are the one who submitted this PR. Thanks!

Nashmod commented 2 months ago

@heasy+react-native-sunmi-printer+1.8.3.patch I created a patchpackage for this too and it seems to work but its diffidently an issue with older devices that ContextCompat.registerReceiver doesnt work. Though it builds properly with it it does crash the app.I have an SunmiV2.

buildscript { ext { buildToolsVersion = "34.0.0" minSdkVersion = 25 compileSdkVersion = 34 targetSdkVersion = 34 kotlinVersion = "1.9.22" ndkVersion = "23.1.7779620" } }

And im also getting the issues.

I encountered this error too. This issue comes from #48. What I did was I just removed that implementation and it worked just fine. To know more about what it does, I suggest to check the mentioned item.

image

Nashmod commented 2 months ago

I seem to have found the issue, no matter how i edit my build.gradle of my app react-native-sunmi-printer still seems to use androidx.core:core:1.7.0 which doesnt have registerReceiver. the fix was to add that as dependency.

I used androud studio->project structure and added androidx.core:core:1.13.1 ad dependency and it worked.

Find a patchpackage below @heasy+react-native-sunmi-printer+1.8.3.patch