square / react-native-square-reader-sdk

React Native Plugin for Square Reader SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Android] BLUETOOTH_CONNECT permission required

smalik02 opened this issue · comments

Describe the issue

Unable to compile the app for android. The compileSdkVersion is 31 and targetSdkVersion is also 31. Even bumping it down to 28/29 does not solve the issue. Testing on a device running android 12.

Adding Bluetooth_connect to AndroidManifest.xml also does not solve the issue.

Error log details:

E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.dyne.staff, PID: 2957
  java.lang.RuntimeException: Unable to create application com.dyne.staff.MainApplication: java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for android.content.AttributionSource@360616cd: GattService getDevicesMatchingConnectionStates
      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6767)
      at android.app.ActivityThread.access$1500(ActivityThread.java:256)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2091)
      at android.os.Handler.dispatchMessage(Handler.java:106)
      at android.os.Looper.loopOnce(Looper.java:201)
      at android.os.Looper.loop(Looper.java:288)
      at android.app.ActivityThread.main(ActivityThread.java:7870)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
   Caused by: java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for android.content.AttributionSource@360616cd: GattService getDevicesMatchingConnectionStates
      at android.os.Parcel.createExceptionOrNull(Parcel.java:2425)
      at android.os.Parcel.createException(Parcel.java:2409)
      at android.os.Parcel.readException(Parcel.java:2392)
      at android.os.Parcel.readException(Parcel.java:2334)
      at android.bluetooth.IBluetoothGatt$Stub$Proxy.getDevicesMatchingConnectionStates(IBluetoothGatt.java:1690)
      at android.bluetooth.BluetoothManager.getDevicesMatchingConnectionStates(BluetoothManager.java:200)
      at android.bluetooth.BluetoothManager.getConnectedDevices(BluetoothManager.java:160)
      at com.squareup.logging.RealBluetoothDevicesCountInitializer.setupInitialConnectedDevices(RealBluetoothDevicesCountInitializer.kt:54)
      at com.squareup.logging.BluetoothAclConnectionReceiver.onEnterScope(BluetoothAclConnectionReceiver.kt:27)
      at shadow.mortar.MortarScope.register(MortarScope.java:199)
      at shadow.com.squareup.mortar.PriorityApplicationScopedKt.registerWithPriority(PriorityApplicationScoped.kt:45)
      at com.squareup.RegisterAppDelegate.onEnterScope(RegisterAppDelegate.java:421)
      at shadow.mortar.MortarScope.register(MortarScope.java:199)
      at com.squareup.RegisterAppDelegate.createAppScope(RegisterAppDelegate.java:332)
      at com.squareup.RegisterAppDelegate.onCreate(RegisterAppDelegate.java:186)
      at com.squareup.sdk.reader.internal.AppBootstrapHolder.onCreate(AppBootstrapHolder.java:23)
      at com.squareup.sdk.reader.ReaderSdk.initialize(ReaderSdk.java:38)
      at com.dyne.staff.MainApplication.onCreate(MainApplication.java:74)
      at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1223)
      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6762)
      at android.app.ActivityThread.access$1500(ActivityThread.java:256) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2091) 
      at android.os.Handler.dispatchMessage(Handler.java:106) 
      at android.os.Looper.loopOnce(Looper.java:201) 
      at android.os.Looper.loop(Looper.java:288) 
      at android.app.ActivityThread.main(ActivityThread.java:7870) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 
D/BluetoothHeadset: Proxy object connected

I am having the same issue. I am able to compile but our app crashes in production for Samsung and Google Pixels. I was able to replicate this issue on the reader-sdk-react-native-quickstart project

Hey,@smalik02 @domhacking

The issue is resolved it is because of the permissions that we need to give in android. The latest code is available so now please check and let me know if you are still facing this issue.

commented

I'm still getting this error despite having BLUETOOTH_CONNECT in my src/main/AndroidManifest.xml file. compile/targetSdkVersion=31. I confirmed that I have the latest code. Is this working for anyone else?

@CharmisG and @zacdemi , I am still having issues as well. I copied the permissions from AndroidManifest.xml of the quickstart and the app still crashed and produced the same error log.

Are there any additional steps to take to make sure the app does not crash with the new code?

We need to do a release within a week.

@CharmisG, Any update on this we need to make an update urgently!

@CharmisG @hukid any update here? This issue needs to be reopened. I'm seeing the same issue in an app I'm working on and in the quickstart.

@tylerc
Sorry for the delay
I'm reopening this issue and checking this in priority and keep updating here.
Thank you !!!

@CharmisG Any update on this? I cannot build my app for Android because of the new Android 12 bluetooth permissions being required. I suspect the "ReaderSdk.initialize(this);" in MainApplication.java needs to be wrapped in a native permission request, but I have no idea how to do that.

To recreate, simply try and run the quickstart app on an Android emulator targeting Android 12 and check the logcat

@CharmisG I don't know if this helps with fixing this, but I've found if you comment out the ReaderSDK Initialize line in the MainApplication.java, run the app, request the BLUETOOTH_CONNECT permission manually from within the RN, then re-run the app with the ReaderSDK initialize line uncommented then it will run.

I'm guessing you need to find a way to natively request that permission and wrap it around the ReaderSDK initialize, or create a callback or method that can initialize the reader from within the RN itself that can be called once the permission request is complete.

At the moment the initialize is happening before you get the chance to request the permission from within the RN app itself.

I simply don't know enough about the java side of things to be able to help further or produce a code solution.

@CharmisG when is this scheduled to be worked on. We have been waiting on this fix for nearly two months and are unable to update our app to google because of this issue.

Would be great to have an estimated time when you will start working on this?

@CharmisG This appears to be working now on v1.4.1

@mormrod
Thank you For your response !!
Please let me know if you will face again !!

@domhacking
Please try with new release. It's Resolved.
Thank You !!!