Apache Cordova Google Analytics Plugin for Android 5

After a year of publishing mobile apps to the Android Marketplace, it seems the whole world is upgrading and if you blink an eye, you will be out of compliance.

So after firing up an emulator running the Android 5.0.1 SDK, all my mobile apps were crashing. I tracked down the error logs and found that there is an issue with the Google Analytics plugin I have been using.

——— beginning of crash
E/AndroidRuntime( 1448): FATAL EXCEPTION: GAThread
E/AndroidRuntime( 1448): java.lang.IllegalArgumentException: Service Intent must be e
xplicit: Intent { act=com.google.android.gms.analytics.service.START (has extras) }
E/AndroidRuntime( 1448): at android.app.ContextImpl.validateServiceIntent(Cont
E/AndroidRuntime( 1448): at android.app.ContextImpl.bindServiceCommon(ContextI
E/AndroidRuntime( 1448): at android.app.ContextImpl.bindService(ContextImpl.ja
E/AndroidRuntime( 1448): at android.content.ContextWrapper.bindService(Context
E/AndroidRuntime( 1448): at com.google.analytics.tracking.android.AnalyticsGms
E/AndroidRuntime( 1448): at com.google.analytics.tracking.android.GAServicePro
E/AndroidRuntime( 1448): at com.google.analytics.tracking.android.GAServicePro
E/AndroidRuntime( 1448): at com.google.analytics.tracking.android.GAThread.ini
E/AndroidRuntime( 1448): at com.google.analytics.tracking.android.GAThread.run

So, there are some major errors. After searching for some answers, the majority of the community alluded that upgrading to Google Analytics Version 3 would fix the issue. The plugin that was crashing the mobile app was using Google Analytics Version 2.

After searching for updates to the existing Google Analytics plugin, I found that it hadn’t been updated in years. There was a fork that tried to accomplish the upgrade to Google Analytics 3, yet it was so hacked with comments and test code that it was unusable without editing the files in the fork itself.

“The solution?”, you ask.

Well, I had to fork the original Google Analytics plugin and upgrade to Google Analytics SDK Version 3 myself.

You can find it here: https://github.com/bengicoder/GAPlugin

I just pointed to this fork, built and ran the mobile project, and now Google Analytics tracking is functional for Android 4 and 5. No crashes and a happy coder.

’nuff said.


About javaclaus

Java Programmer, Code master, mountain biker, snowboarder, etc.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s