当前位置:   article > 正文

重要:升级 Android14 后出现报错:One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified ……_com.jeremyliao.liveeventbus.core.liveeventbuscore.

com.jeremyliao.liveeventbus.core.liveeventbuscore.get

老项目升级到Android14出现错误:

  1. java.lang.ExceptionInInitializerError
  2. at com.jeremyliao.liveeventbus.core.LiveEventBusCore.get(LiveEventBusCore.java:49)
  3. at com.jeremyliao.liveeventbus.LiveEventBus.get(LiveEventBus.java:35)
  4. at com.lib.common.ui.base.CommonActivity.initEvent(CommonActivity.kt:53)
  5. at com.lib.common.ui.base.CommonActivity.onCreate(CommonActivity.kt:29)
  6. at com.lib.common.ui.activity.DeviceMainActivity.onCreate(DeviceMainActivity.kt:141)
  7. at android.app.Activity.performCreate(Activity.java:8595)
  8. at android.app.Activity.performCreate(Activity.java:8573)
  9. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
  10. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3764)
  11. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922)
  12. at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
  13. at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
  14. at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
  15. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
  16. at android.os.Handler.dispatchMessage(Handler.java:106)
  17. at android.os.Looper.loopOnce(Looper.java:205)
  18. at android.os.Looper.loop(Looper.java:294)
  19. at android.app.ActivityThread.main(ActivityThread.java:8177)
  20. at java.lang.reflect.Method.invoke(Native Method)
  21. at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
  22. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
  23. Caused by: java.lang.SecurityException: com.lydsto.robotvacuum: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
  24. at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
  25. at android.os.Parcel.createException(Parcel.java:3041)
  26. at android.os.Parcel.readException(Parcel.java:3024)
  27. at android.os.Parcel.readException(Parcel.java:2966)
  28. at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5684)
  29. at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852)
  30. at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792)
  31. at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780)
  32. at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755)
  33. at com.jeremyliao.liveeventbus.core.LiveEventBusCore.registerReceiver(LiveEventBusCore.java:127)
  34. at com.jeremyliao.liveeventbus.core.LiveEventBusCore.<init>(LiveEventBusCore.java:84)
  35. at com.jeremyliao.liveeventbus.core.LiveEventBusCore.<init>(LiveEventBusCore.java:39)
  36. at com.jeremyliao.liveeventbus.core.LiveEventBusCore$SingletonHolder.<clinit>(LiveEventBusCore.java:45)
  37. at com.jeremyliao.liveeventbus.core.LiveEventBusCore.get(LiveEventBusCore.java:49) 
  38. at com.jeremyliao.liveeventbus.LiveEventBus.get(LiveEventBus.java:35) 

根据错误定位到问题是由于使用了一个三方库导致的:

implementation 'com.jeremyliao:live-event-bus:1.7.3'

进一步分析三方库错误原因:

Caused by: java.lang.SecurityException: com.lydsto.robotvacuum: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

错误描述翻译过就是:在注册广播接收器(application.registerReceiver())时需要 指定导出标志 为RECEIVER_EXPORTED 或者 RECEIVER_NOT_EXPORTED;

查看三方库源码进一步确认问题:

确实是没有根据版本判断进行flags赋值,修改后:

问题解决。

总结:Android14 强制要求  注册广播接收器(application.registerReceiver())时需要 指定导出标志 为RECEIVER_EXPORTED 或者 RECEIVER_NOT_EXPORTED。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/630751
推荐阅读
相关标签
  

闽ICP备14008679号