I have upgraded my app to support SDK 26 and now Google Analytics causes crashes when running on Android Oreo:
Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.google.android.gms.analytics.AnalyticsReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.gms.analytics.ANALYTICS_DISPATCH cmp=com.example.android/com.google.android.gms.analytics.AnalyticsService }: app is in background uid UidRecord{3f302e5 u0a107 RCVR idle procs:1 seq(0,0,0)} at android.app.ActivityThread.handleReceiver(ActivityThread.java:3259) at android.app.ActivityThread.-wrap17(Unknown Source) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.gms.analytics.ANALYTICS_DISPATCH cmp=com.example.android/com.google.android.gms.analytics.AnalyticsService }: app is in background uid UidRecord{3f302e5 u0a107 RCVR idle procs:1 seq(0,0,0)} at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1505) at android.app.ContextImpl.startService(ContextImpl.java:1461) at android.content.ContextWrapper.startService(ContextWrapper.java:644) at android.content.ContextWrapper.startService(ContextWrapper.java:644) at com.google.android.gms.internal.zzaot.onReceive(Unknown Source:68) at com.google.android.gms.analytics.AnalyticsReceiver.onReceive(Unknown Source:11) at android.app.ActivityThread.handleReceiver(ActivityThread.java:3252) at android.app.ActivityThread.-wrap17(Unknown Source) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
This is my relevant Manifest:
<meta-data
android:name="com.google.android.gms.analytics.globalConfigResource"
android:resource="@xml/analytics"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<!-- Optionally, register AnalyticsReceiver and AnalyticsService to support background
dispatching on non-Google Play devices -->
<receiver
android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH"/>
</intent-filter>
</receiver>
<service
android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true"
android:exported="false"/>
<!-- Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable
installation campaign reporting -->
<receiver
android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
<service
android:name="com.google.android.gms.analytics.CampaignTrackingService"
android:exported="true"/>
Having hundreds of Oreo devices crashing due to this in past 24 hours. Seems to be affecting only on install. I am going to try and add android:permission="android.permission.BIND_JOB_SERVICE" to the 2 analytics services and see. Will report.
I Will be happy to provide more info if needed. Thanks