30

I use Google Analytics in my Android App and it works well. After updating the SDK (google play service) to the current version (6587000) the app hangs up at startup at following line 8 of 10 times:

GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);

There is no error in console. I added Achievements and Leaderboards too, but Analytics is called first. I also changed the context, but that works sometimes and sometimes not.

The only time I get a reproducable result is, when I remove following lines from AndroidManifest.xml. Then there is no freeze at startup anymore.

<meta-data 
        android:name="com.google.android.gms.analytics.globalConfigResource"
        android:resource="@xml/analytics_global_config" />

But my configuration is correct:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <string name="ga_appName">TestAppName</string>
  <string name="ga_appVersion">Version1.0</string>
  <string name="ga_logLevel">verbose</string>
  <integer name="ga_dispatchPeriod">1000</integer>
  <bool name="ga_dryRun">true</bool>
</resources>

And if I change the configuration there is the same result: 8 of 10 times the App freezes at startup.

Does someone have a clue what the problem is or what else I can check to make my app running again without freezing at startup?

  • According to https://productforums.google.com/forum/#!category-topic/analytics/report-bugs/RAgDNYFk6jo , this bug has been fixed in Play Services 6.5.99 – gnuf Jan 08 '15 at 02:28
  • I downgraded to 'com.google.android.gms:play-services:6.1.71' and now it works. I hope it will be fixed soon. – petrnohejl Jan 11 '15 at 21:25

3 Answers3

37

i had similar i removed the below code and application runs..

<meta-data 
        android:name="com.google.android.gms.analytics.globalConfigResource"
        android:resource="@xml/analytics_global_config" />

and add following code for getTracker class... build the GoogleAnalytics using java code rather than XML approch

synchronized Tracker getTracker(TrackerName trackerId) {
        Log.d(TAG, "getTracker()");
        if (!mTrackers.containsKey(trackerId)) {
            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);

            // Global GA Settings
            // <!-- Google Analytics SDK V4 BUG20141213 Using a GA global xml freezes the app! Do config by coding. -->
            analytics.setDryRun(false);

            analytics.getLogger().setLogLevel(Logger.LogLevel.INFO);
            //analytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);

            // Create a new tracker
            Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(R.xml.ga_tracker_config) : null;
            if (t != null) {
                t.enableAdvertisingIdCollection(true);
            }
            mTrackers.put(trackerId, t);
        }
        return mTrackers.get(trackerId);
    }
  • 9
    I had exactly the same issue, and it took me 3 days to find out the root cause. This is a very unacceptable bug because it's just what Google tells us to do in Google Analytics tutorial. – cwhsu Dec 23 '14 at 02:04
  • Such an unexpected and difficult to debug issue. Version control was the only thing that lead me to guess that this was caused by a bug in the SDK. Thanks so much for this workaround! – alexgophermix Mar 16 '15 at 00:29
3

This is a know bug in Google Play Services 6.5.

The issue is fixed in Google Play Services 7.0 that was released in March 19, 2015. Upgrading to 7.0 fixes the deadlock. https://developer.android.com/google/play-services/index.html

djabi
  • 5,601
  • 18
  • 25
1

I had the same ANR issue every time I was calling GoogleAnalytics.getInstance(this). The problem seems to appear when the Google Play Services version in the app is not matching the one installed on the device.

I solved this by checking if Google Play Services is "available":

if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) {
    GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
    // Create your tracker...
}
agirardello
  • 2,895
  • 22
  • 22
  • While checking GPS availability is a good practice, this doesn't seem to solve the problem for me. – Adam Feb 19 '15 at 23:43
  • GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) is deprecated use GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(ctx) – Kenumir Jul 15 '15 at 13:05