Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Android 14 / api 34 Crashing issue on android 14 devices #663

Closed
Marcello17 opened this issue Jul 12, 2024 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@Marcello17
Copy link

Describe the bug
I've upgraded my app using :
compileSdkVersion = 34
targetSdkVersion = 34

and it gave this error:
FATAL EXCEPTION: main

java.lang.RuntimeException: Unable to start activity ComponentInfo{mypackagename/MainActivity}: java.lang.SecurityException: mypackagenamei: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

I see the files show this:
context.registerReceiver(stateReceiver, intentFilter)
does this need to be adjusted to accommodate android 14?

To Reproduce
Steps to reproduce the behavior:
Set the API to 34:

compileSdkVersion = 34
targetSdkVersion = 34

Screenshots
image

Plugin version:

  • @capacitor-community/bluetooth-le: 6.0.0 or 3.1.1 [ Tried on both]

Smartphone (please complete the following information):

  • Device: Samsung S21 / S24
  • OS: Android 14
@Marcello17 Marcello17 added the bug Something isn't working label Jul 12, 2024
@peitschie
Copy link
Collaborator

Just copying over my notes from don/cordova-plugin-ble-central#1020 (comment)

Relevant documentation from Android on this:

Although these are all system broadcasts, because they're being registered via an Activity, they're effectively context-registered receivers, and thus need a RECEIVER_EXPORTED flag, as the app needs intents coming from outside the application itself (i.e., from the system).

@lajith111
Copy link

lajith111 commented Jul 17, 2024

Same issue happen on cordova capacitor. Please check https://github.com/cordova-sms/cordova-sms-plugin/pull/233/files
Now i dont have android 14 device to check but in kotlin may be this will solve

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) //or andoid 14
{
   context.registerReceiver(bondStateReceiver, intentFilter,Context.RECEIVER_EXPORTED)
}
else
{
  context.registerReceiver(bondStateReceiver, intentFilter)
}

@peitschie
Copy link
Collaborator

@Marcello17 or @lajith111 do either you have the capacity to see if #667 fixes the problem for you?

@Marcello17
Copy link
Author

Marcello17 commented Jul 17, 2024

@Marcello17 or @lajith111 do either you have the capacity to see if #667 fixes the problem for you?

I've tested out your solution and it didn't work BUT it looks like it's not a ble capacitor issue.

I've used your method on the @capacitor/share which also had a broadcast receiver and it worked!

But then I realized that I also had to update the @cacpacitor/share

from version '5.0.7' to the latest '6.0.1'

so in the end for me it was the @capacitor/share plugin in the SharePlugin.java file that was causing the issue

@pwespi
Copy link
Member

pwespi commented Jul 22, 2024

Thank you @Marcello17 for reporting back.

I can confirm that with

compileSdkVersion = 34
targetSdkVersion = 34

my test app works fine on an Android 14 device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants