1

I switched from using Google play services 6.1 to 6.5. GoogleAnalytics reached a deadlock on:

getInstance(context); 

I found this question: Android GoogleAnalytics getInstance where the second answer recommends to remove the meta-data from the Manifest file.

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

Since global_tracker.xml contained the following:

<resources>
    <integer name="ga_sessionTimeout">300</integer>
    <bool name="ga_reportUncaughtExceptions">true</bool>
    <integer name="ga_dispatchPeriod">30</integer>
</resources>

I replaced the xml with these programmatical configurations:

GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(mContext);
googleAnalytics.setLocalDispatchPeriod(30);

mGATracker = googleAnalytics.newTracker(mTrackerId);
mGATracker.setSessionTimeout(300);
mGATracker.enableExceptionReporting(true);

What is the reason the xml configuration no longer works and what are the implications of configuring programmatically?

Community
  • 1
  • 1
JY2k
  • 2,879
  • 1
  • 31
  • 60

1 Answers1

3

Update:

Please take a look at iOSched 2014: https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/util/AnalyticsManager.java

Original:

You are not the only one. Google Play Services 6.5.87 has a deadlock issue.

Please follow:

https://code.google.com/p/android/issues/detail?id=82157

From the link above:

Google Analytics blocks Android App

Remove this from the AndroidManifest.xml:

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

Using the Google Analytics programmacitally vs using the XML:

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);
}

Not recommended:

Until Google fixes their deadlock issue, use:

compile 'com.google.android.gms:play-services:6.1.71'

instead of:

compile 'com.google.android.gms:play-services:6.5.87'
Community
  • 1
  • 1
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • My solution works. I was asking why the configuration xml doesn't work. – JY2k Jan 08 '15 at 15:25
  • @JY2k My "solution" worked as well. Look at the first link I gave you, it happens on some devices. Also, what version of Google Play Services are you using exactly? – Jared Burrows Jan 08 '15 at 15:41
  • your solution doesn't answer my question. nor does it help any1 looking to use 6.5.+. you suggest to use 6.1.71. I know 6.1.71 works but I want to use 6.5.+ so I can select which APIs to import. – JY2k Jan 08 '15 at 16:15
  • Obviously you did not read the thread I posted. Google Play Services has an issue. I'll update my answer with a link and example could the synchronizes the tracking code. – Jared Burrows Jan 08 '15 at 16:18
  • WHat would be the equivalent of `compile 'com.google.android.gms:play-services:6.5.87'` in eclipse for the int value `6171000` so far I am just guessing! – Skynet Mar 19 '15 at 06:35
  • Just found a way of doing that, You can find it under google-play-services_lib>res>values>version.xml if you wish to add the number rather than @integer/google_play_services_version. – Skynet Mar 19 '15 at 06:38
  • @Skynet Don't avoid the problem, deal with the issue. – Jared Burrows Mar 19 '15 at 10:59
  • No I just started it in the eye, I was trying to use the v7 lib but had to upgrade all my libraries. So to say there is a bug in the latest version of play services lib documented [here](https://code.google.com/p/android/issues/detail?id=82157). The only thing which worked for me was to downgrade to rev-21 of the play lib. – Skynet Mar 19 '15 at 11:05
  • Few things here: v7 lib? Are you talking about AppCompat? rev21 play lib? You mean Google Play Services 6.5.87? There is no reason to downgrade Google play, the answer in my answer. The link you posted is in my answer as well. – Jared Burrows Mar 19 '15 at 11:09
  • I agree with you that instead of xml I should use the Java method, however I am also using GCM which is also dependent on the play lib. I will definitely give a try to your first solution, is that what you strongly suggest? – Skynet Mar 19 '15 at 11:12
  • Use this link: http://stackoverflow.com/questions/27533679/google-analytics-blocks-android-app/27542483#27542483. Also, take a look at how Google does it here: https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/util/AnalyticsManager.java – Jared Burrows Mar 19 '15 at 11:16
  • Thanks @JaredBurrows, Ill have a look there :) – Skynet Mar 19 '15 at 11:27