Reputation: 2909
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?
Upvotes: 1
Views: 1155
Reputation: 55527
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
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);
}
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'
Upvotes: 3