yandex/mapkit-android-demo

One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

olmicron opened this issue · 6 comments

На 14й версии андроида, при открытии карты в своём приложении получаю ошибку:

Cannot register receiver
java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
	at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
   	at android.os.Parcel.createException(Parcel.java:3041)
  	at android.os.Parcel.readException(Parcel.java:3024)
 	at android.os.Parcel.readException(Parcel.java:2966)
	at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5684)
	at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852)
	at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792)
	at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780)
  	at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755)
 	at com.yandex.runtime.connectivity.internal.ConnectivitySubscription$1.run(ConnectivitySubscription.java:53)
 	at android.os.Handler.handleCallback(Handler.java:958)
	at android.os.Handler.dispatchMessage(Handler.java:99)
 	at android.os.Looper.loopOnce(Looper.java:205)
	at android.os.Looper.loop(Looper.java:294)
  	at android.app.ActivityThread.main(ActivityThread.java:8177)
   	at java.lang.reflect.Method.invoke(Native Method)
     	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
   	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

"Исключение" в лог выбрасывается отсюда (из либы):

    public void subscribe(NativeObject promise) {
        this.nativePromise = promise;
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            public void run() {
                IntentFilter filter = new IntentFilter();
                filter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
                filter.addAction("com.yandex.runtime.internal.CONNECTIVITY_CHANGED");
                filter.addAction("android.os.action.DEVICE_IDLE_MODE_CHANGED");
                filter.addAction("android.os.action.LIGHT_DEVICE_IDLE_MODE_CHANGED");

                try {
                    Runtime.getApplicationContext().registerReceiver(ConnectivitySubscription.this, filter);
                    ConnectivitySubscription.this.isRegistered = true;
                    ConnectivitySubscription.this.update(ConnectivitySubscription.this.status());
                } catch (SecurityException var3) {
                    Log.e(ConnectivitySubscription.TAG, "Cannot register receiver", var3);
                }

            }
        });
    }

Версия карты/либы: 4.4.0-lite
CompileSdk и targetSdk в приле: 34

П.С. Понимаю, что это не краш, но всё же - не люблю когда в приле возникают ошибки :)

На 4.4.0-full такое же исключение, возникает при указании targetSdk 34.
При регистрации BroadcastReceiver нужно передавать флаг RECEIVER_EXPORTED или RECEIVER_NOT_EXPORTED
Подробнее: https://developer.android.com/about/versions/14/behavior-changes-14#runtime-receivers-exported

@olmicron вполне себе краш :) просто сейчас в библиотеке указан android:targetSdkVersion="30", но если укажут 34 и не добавят обработку для тирамису и выше, то приложение будет крашится. Хотя у них там try-catch, они об этом даже не узнают. Мы у себя в проекте уже с этим столкнулись, хорошо есть Firebase и вовремя заметили

А тут как и написали нужна такая обработка

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
     Runtime.getApplicationContext().registerReceiver(ConnectivitySubscription.this, filter, RECEIVER_EXPORTED/RECEIVER_NOT_EXPORTED);
} else {
     Runtime.getApplicationContext().registerReceiver(ConnectivitySubscription.this, filter);
}

Решили вопрос с вылетами.

E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): Cannot register receiver E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): java.lang.SecurityException: com.example.my_project: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.os.Parcel.createExceptionOrNull(Parcel.java:3057) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.os.Parcel.createException(Parcel.java:3041) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.os.Parcel.readException(Parcel.java:3024) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.os.Parcel.readException(Parcel.java:2966) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5684) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at com.yandex.runtime.connectivity.internal.ConnectivitySubscription$1.run(ConnectivitySubscription.java:53) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.os.Handler.handleCallback(Handler.java:958) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.os.Handler.dispatchMessage(Handler.java:99) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.os.Looper.loopOnce(Looper.java:205) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.os.Looper.loop(Looper.java:294) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.app.ActivityThread.main(ActivityThread.java:8177) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at java.lang.reflect.Method.invoke(Native Method) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): Caused by: android.os.RemoteException: Remote stack trace: E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:13927) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2570) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2720) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.os.Binder.execTransactInternal(Binder.java:1344) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): at android.os.Binder.execTransact(Binder.java:1275) E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): E/com.yandex.runtime.connectivity.internal.ConnectivitySubscription(10744): Cannot register receiver

не то что бы решено. SDK 33/34

yandex_maps_mapkit: ^4.6.1-beta2

Словил такую же проблему сегодня, пишу на Flutter, использую версию
https://pub.dev/packages/yandex_mapkit (v4.0.2)
и
"com.yandex.android:maps.mobile:4.5.1-lite"

Same problim with 4.6.1-lite