Search code examples
androidadmobads

ConcurrentModificationException in Android.onCreate (com.google.android.measurement.internal)


This recent crash started happening on across every Android versions within various device manufacturers. I believe it has something to do with either advertisements or one of Google's components.

I opened an issue myself here: https://issuetracker.google.com/issues/149665852

Related information about the devices (from 2k users there are 48 exceptions from 43 users so far, happened in 3 days)

enter image description here

Stack trace (package name is hidden due to confidentiality):

Caused by java.util.ConcurrentModificationException
       at androidx.collection.SimpleArrayMap.put + 461(SimpleArrayMap.java:461)
       at com.google.android.gms.measurement.internal.zzin.zza + 108(zzin.java:108)
       at com.google.android.gms.measurement.internal.zzid.onActivityCreated + 11(zzid.java:11)
       at android.app.Application.dispatchActivityCreated + 189(Application.java:189)
       at android.app.Activity.onCreate + 962(Activity.java:962)
       at androidx.core.app.ComponentActivity.onCreate + 81(ComponentActivity.java:81)
       at androidx.activity.ComponentActivity.onCreate + 149(ComponentActivity.java:149)
       at androidx.fragment.app.FragmentActivity.onCreate + 313(FragmentActivity.java:313)
       at androidx.appcompat.app.AppCompatActivity.onCreate + 106(AppCompatActivity.java:106)
       at com.example.myapp.MainActivity.onCreate + 35(MainActivity.java:35)
       at android.app.Activity.performCreate + 6147(Activity.java:6147)
       at android.app.Instrumentation.callActivityOnCreate + 1112(Instrumentation.java:1112)
       at android.app.ActivityThread.performLaunchActivity + 2498(ActivityThread.java:2498)
       at android.app.ActivityThread.handleLaunchActivity + 2625(ActivityThread.java:2625)
       at android.app.ActivityThread.access$700 + 183(ActivityThread.java:183)
       at android.app.ActivityThread$H.handleMessage + 1484(ActivityThread.java:1484)
       at android.os.Handler.dispatchMessage + 111(Handler.java:111)
       at android.os.Looper.loop + 194(Looper.java:194)
       at android.app.ActivityThread.main + 5667(ActivityThread.java:5667)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke + 372(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 962(ZygoteInit.java:962)
       at com.android.internal.os.ZygoteInit.main + 757(ZygoteInit.java:757)

Knowledge about the exception: It occurs if a function tries to modify a list while another function is iterating through it. So I guess this is a race condition between two threads or more.

More details:

First of all, we do not use any SimpleArrayMap. So I am sure the exception is not related to our code in any way.

The call to com.example.myapp.MainActivity.onCreate + 35(MainActivity.java:35) this line points to this:

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState); // stack trace points here

    // rest of the code
}

The stack trace points to onCreate but the actual responsible one is here (which is at the top of the stack trace):

at androidx.collection.SimpleArrayMap.put + 461(SimpleArrayMap.java:461)
at com.google.android.gms.measurement.internal.zzin.zza + 108(zzin.java:108)
at com.google.android.gms.measurement.internal.zzid.onActivityCreated + 11(zzid.java:11)

Now, a couple of details: This application uses Firebase Analytics, AdMob with various ad networks such as AppLovin, Ironsource etc... and in app billing. I'm not sure what com.google.android.gms.measurement is exactly, but the source of the exception seems to be coming from there.

From what I understand, this component attaches an object that intercepts activity lifecycles through this using Application.registerActivityLifecycleCallbacks. Now, most of the libraries do that but none we use cause an exception like this. So, I am not sure how to intercept and move on with it, because I'm afraid wrapping this to a try-catch doesn't look like a good "solution". I'm not even sure if it will resolve the situation because I think another exception will occur after that, such as You must call Activity.onCreate().

I'm stumped and I don't know what to do besides asking here. The closest thing I've found was this but there are no answers on that either.

If it helps, here are the dependencies we use. (our build.gradle file)

implementation fileTree(dir: 'libs', include: '*.aar')
implementation 'com.google.firebase:firebase-core:17.2.1'
implementation 'com.google.firebase:firebase-config:19.1.1'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.browser:browser:1.2.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3'
implementation 'androidx.preference:preference:1.1.0'
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.google.android.gms:play-services-base:17.1.0'
implementation 'com.airbnb.android:lottie:3.0.7'
implementation 'com.google.android.play:core:1.6.4'
implementation 'com.github.anrwatchdog:anrwatchdog:1.4.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.google.android.gms:play-services-ads:18.3.0'
implementation 'com.google.android.ads:mediation-test-suite:1.2.2'
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.google.ads.mediation:applovin:9.8.0.0'
implementation 'com.google.ads.mediation:facebook:5.6.0.0'
implementation 'com.mopub.volley:mopub-volley:2.1.0'
implementation('com.mopub:mopub-sdk:5.7.0@aar') {
    transitive = true
    exclude module: 'libAvid-mopub' // To exclude AVID
    exclude module: 'moat-mobile-app-kit' // To exclude Moat
}
implementation 'com.google.ads.mediation:mopub:5.7.0.0'
implementation 'com.google.ads.mediation:inmobi:7.3.0.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.android.gms:play-services-plus:17.0.0'
implementation 'com.google.ads.mediation:tapjoy:12.3.1.0'
implementation 'com.unity3d.ads:unity-ads:3.1.0'
implementation 'com.google.ads.mediation:unity:3.1.0.0'

Any help is appreciated, thank you very much.


Solution

  • The recent Firebase Analytics library 17.2.2 causing the issue for me. If you are using the Firebase Analytics, you need to revert back to the older version of the Firebase Analytics like 17.2.1 will fix the issue.

    Update: It seems Firebase fixed the issue on their 17.2.3 version.