I set up Google Analytics v4 for Unity using the provided plugin. It works fine for both editor and on iOS devices and the logged events and so on are received online. However on android I get a series of exceptions at runtime, even though I set up everything like it should (edited the manifest and imported the plugin) and encounter no issues when building.
First that the google analytics class can not be found, which seems to be comon:
UnityEngine.AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.analytics.GoogleAnalytics
I/Unity (13784): java.lang.ClassNotFoundException: com.google.android.gms.analytics.GoogleAnalytics
I/Unity (13784):
at java.lang.Class.classForName(Native Method)
I/Unity (13784):
at java.lang.Class.forName(Class.java:308)
I/Unity (13784):
at java.lang.Class.forName(Class.java:272)
I/Unity (13784):
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
I/Unity (13784):
at com.unity3d.player.UnityPlayer.a(Unknown Source)
I/Unity (13784):
at com.unity3d.player.UnityPlayer$b.run(Unknown Source)
I/Unity (13784): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.analytics.GoogleAnalytics"
As a fix for that I found a common solution (e.g. here), stating:
Copy play-services-analytics-8.4.0.aar from {android-sdk}\extras\google\m2repository\com\google\android\gms\play-services-analytics\8.4.0 to your Assets/Plugins/Android folder.
Doing this I got rid of the exception above, but introduced a new one:
UnityEngine.AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzx;
I/Unity (13051): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/zzx;
I/Unity (13051):
at com.google.android.gms.analytics.internal.zzf.zzaa(Unknown Source)
I/Unity (13051):
at com.google.android.gms.analytics.GoogleAnalytics.getInstance(Unknown Source)
I/Unity (13051):
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
I/Unity (13051):
at com.unity3d.player.UnityPlayer.a(Unknown Source)
I/Unity (13051):
at com.unity3d.player.UnityPlayer$b.run(Unknown Source)
For this one I can’t find a solution so far and am currently stuck. I gues something is wrong with my setup, but I can't solve it. Any help would be greatly appreciated
Edit: I changed to google analytics v3 (just exchanged some of the source classes that come with the unity plugin in and added some casts) and now it works on the device. So is the android version of my test device incompatible with google analytics v4? Can't really tell, some more insight from the debugger would be helpfull.
It is a conflict between google play services and analytics as stated on https://github.com/googleanalytics/google-analytics-plugin-for-unity/issues/51#issuecomment-98633184
` you can download and include the v23 play services jar from http://dl.google.com/android/repository/google_play_services_7095000_r23.zip
It worked for me with the latest unity sdk
I'm getting the exact same behaviour. Rolling back to V3 solved the issue.