Building with Android 11 results in runtime crash

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?

Can you provide some details about your setup? What version of the sdk your using? Can you reproduce this is a sample project outside of your app?

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.

Any news regarding this issue?

Any news?
I have the exact problem.
All ok when I take your dependency out.
Please inform me so I can continue working with you.

Best regards
Arbel

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 met the same problem

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…

Moving my app the latest target sdk (30) and faced with the same issue, why don’t you check connectivity in some other way?

They released a new version (3.4.8), it seems to have fixed it.

Last version is
implementation ‘com.google.ads.mediation:unity:3.4.6.1’

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

I have the same error … Still not resolved?
Edit: all works in unity 2019.4.10f1

Started noticing more reported crashes on the Play Dashboard since Android 11 came out. Traced it back to this same error. Using 2018.4.12f1

Update: (Workaround) I’m using ad mediation, so I was able to trace it back to Unity Ads. Unity Ads On = Yes Crashing… Unity Ads Off = No Crashing.

My latest build is having the same problem on Android 11 devices. I’m using Unity 2018.4.27f1and targeting API level 28.

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

1 Like

Hi! I’m facing the same problem using Unity 2020.1.16f1, targeting API 30 and Unity Advertisement version 3.6.1

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

Same scenario for me: 2019.4, Unity Ads 3.6.1 - only works with target API 29, crashes on API 30.