We downloaded the new Android 11 SDK to test our apps on the new OS, but UnityAds keeps crashing with the following error:
java.lang.SecurityException: getDataNetworkTypeForSubscriber
at android.os.Parcel.createExceptionOrNull(Parcel.java:2373)
at android.os.Parcel.createException(Parcel.java:2357)
at android.os.Parcel.readException(Parcel.java:2340)
at android.os.Parcel.readException(Parcel.java:2282)
at com.android.internal.telephony.ITelephony$Stub$Proxy.getNetworkTypeForSubscriber(ITelephony.java:8711)
at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2945)
at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2909)
at com.unity3d.services.core.connectivity.ConnectivityMonitor.connectionStatusChanged(ConnectivityMonitor.java:162)
at com.unity3d.services.core.connectivity.ConnectivityNetworkCallback.onCapabilitiesChanged(ConnectivityNetworkCallback.java:48)
at android.net.ConnectivityManager$NetworkCallback.onAvailable(ConnectivityManager.java:3346)
at android.net.ConnectivityManager$CallbackHandler.handleMessage(ConnectivityManager.java:3626)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.os.HandlerThread.run(HandlerThread.java:67)
It seems that it requires the READ_PHONE_STATE permission, but this wasn’t required in the previous OS versions. Is there a way to get around this issue without having to request an adicional permission from the user?
I’m running the project in Android Studio 4.0 targeting API level 30 and using UnityAds 3.4.6.
Here is a simple project where you replicate the issue: https://gitlab.com/marcobat1989/testads/-/tree/master
You have to add a GameId to the MainActivity before running, it should crash after a couple of seconds from opening the app.
The issue goes away if you go to the app’s settings and give the READ_PHONE_STATE permission. If you change to a previous Android API level (e.g. 29) the crash does not occur.
Hi Pedroatg, we have reproduced the issue using the provided project and are currently investigating a solution. I’ll reply here when we have more information.
Fatal Exception: java.lang.SecurityException: getDataNetworkTypeForSubscriber
at android.os.Parcel.createExceptionOrNull(Parcel.java:2373)
at android.os.Parcel.createException(Parcel.java:2357)
at android.os.Parcel.readException(Parcel.java:2340)
at android.os.Parcel.readException(Parcel.java:2282)
at com.android.internal.telephony.ITelephony$Stub$Proxy.getNetworkTypeForSubscriber(ITelephony.java:8722)
at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2945)
at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2909)
at com.unity3d.services.core.connectivity.ConnectivityMonitor.connectionStatusChanged(ConnectivityMonitor.java:162)
at com.unity3d.services.core.connectivity.ConnectivityNetworkCallback.onCapabilitiesChanged(ConnectivityNetworkCallback.java:48)
at android.net.ConnectivityManager$NetworkCallback.onAvailable(ConnectivityManager.java:3347)
at android.net.ConnectivityManager$CallbackHandler.handleMessage(ConnectivityManager.java:3627)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.os.HandlerThread.run(HandlerThread.java:67)
I tried opening a ticket, I was told that they haven’t fixed it yet and to expect a reply here.
In the mean time, they recommended targeting Android 10 instead of 11…
I’m getting a lot of crashes right now.
I’m using Google AdMob Unity SDK v5.3.0 (Unity 2018.4.23f1) with Unity mediation adapter version:
com.google.ads.mediation:unity:3.4.6.1
In the change log for Unity Monetization (Unity Ads):
Version: 3.4.8 • Aug 7, 2020
3.4.8 [iOS] Enable support for SKAdNetwork
[iOS] Enable support for App Tracking Transparency [Android] Fix crash in Android API level 30 with getNetworkType
Edit: I’ve changed the target for API 29 and it worked! For some reason Google has refused my update but I’m working on it, at least it’s not crashing on Android 11 anymore