0

I recently started adding Google Analytics integration into my Application. To do so I've been following the steps provided here: https://developers.google.com/analytics/devguides/collection/android/v4/

I had no Application class so I created one with the basic implementation provided here: http://www.javacodegeeks.com/2014/04/working-with-google-analytics-api-v4-for-android.html

In each Activity I added the following snippets:

@Override
protected void onStart() {
    super.onStart();
    //Get an Analytics tracker to report app starts & uncaught exceptions etc.
    GoogleAnalytics.getInstance(this).reportActivityStart(this);
}

@Override
protected void onStop() {
    super.onStop();
    //Stop the analytics tracking
    GoogleAnalytics.getInstance(this).reportActivityStop(this);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Get a Tracker (should auto-report)
    ((MyApplication) getApplication()).getTracker(MyApplication.TrackerName.APP_TRACKER);
    //...
}

and I started seeing live users on my corresponding Analytics page.

For whatever reason when I start the App via fresh install from Android Studio it works fine. However when I kill the app through the task manager and start it again it displays only a blank screen and provides the following error.

E/Trace﹕ error opening trace file: No such file or directory (2)
D/ActivityThread﹕ setTargetHeapUtilization:0.25
D/ActivityThread﹕ setTargetHeapIdealFree:8388608
D/ActivityThread﹕ setTargetHeapConcurrentStart:2097152
W/dalvikvm﹕ VFY: unable to resolve virtual method 36489: Ljava/lang/ReflectiveOperationException;.printStackTrace ()V
W/dalvikvm﹕ VFY: unable to resolve virtual method 11845: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
W/dalvikvm﹕ VFY: unable to resolve virtual method 11842: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
W/dalvikvm﹕ VFY: unable to resolve virtual method 11848: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
W/dalvikvm﹕ VFY: unable to resolve virtual method 9471: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
W/dalvikvm﹕ VFY: unable to resolve virtual method 565: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
W/dalvikvm﹕ VFY: unable to resolve virtual method 587: Landroid/content/res/TypedArray;.getType (I)I

I feel like I'm missing something super basic here. Can anyone point me in the right direction?

I looked through some of the related issues on Stack Overflow and it doesn't look like any cover my current case.

I'm using play services version 65870000 and have the following two lines added to my manifest:

<!--This meta-data tag is required to use Google Play Services.-->
<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

<!-- Google Analytics Version v4 needs this value for easy tracking -->
<meta-data
    android:name="com.google.android.gms.analytics.globalConfigResource"
    android:resource="@xml/global_tracker" />

My current test device is a LG Lucid 2 (vs870) running Android 4.1.2

If there's any other code snippets I should include, please feel free to ask.

Note: I checked out my previous tag and this issue is not present so it must be related to creating this Application class, src/main/res/xml/app_tracker.xml and src/main/res/xml/global_tracker.xml config files and adding required analytics setup code in activities.

Thanks in advance for any help or suggestions!

Edit: If I remove the following lines from my MainActivity the app starts up properly every time again:

// onStart
GoogleAnalytics.getInstance(this).reportActivityStart(this);
// onStop
GoogleAnalytics.getInstance(this).reportActivityStop(this);
// onCreate
((MyApplication) getApplication()).getTracker(MyApplication.TrackerName.APP_TRACKER);
alexgophermix
  • 4,189
  • 5
  • 32
  • 59
  • Have you change the application class to be your MyApplication by setting the name attribute of application element in your ApplicationManifest.xml? It should looks something like this: ... The log lines you provided show that someone is trying to process the call stack. This someone is likely Google Analytics trying to send a crash report caused by ((MyApplication) getApplication()). Just a wild guess.... – djabi Mar 16 '15 at 17:53
  • I think those lines were not actually causing the ANR. See my answer below. There was a bug in the Analytics SDK itself that was causing the crash. – alexgophermix Mar 16 '15 at 18:02

1 Answers1

0

Found it! Bug in Google Analytics SDK causes an ANR when using XML for GA global configuration. AKA you can't use this Meta tag:

<!-- Google Analytics Version v4 needs this value for easy tracking -->
<meta-data
    android:name="com.google.android.gms.analytics.globalConfigResource"
    android:resource="@xml/global_tracker" />

See this amazing answer for more: https://stackoverflow.com/a/27542483/740474

Community
  • 1
  • 1
alexgophermix
  • 4,189
  • 5
  • 32
  • 59