5

I'm trying to integrate Google Analytics in my Android App, but I'm having trouble. (SEE EDIT)

Following https://developers.google.com/analytics/devguides/collection/android/v4/ when I create

HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();

Android Studio tell me that cannot resolve symbol Tracker.

I already use Google Play Services in my app to serve admob, so I don't understand why I cannot import com.google.android.gms.analytics.Tracker

In AndroidManifest.xml i have

<meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version"/>

What am I missing?

EDIT
i'm following also: How to integrate Google Analytics in Android app and http://java.dzone.com/articles/working-google-analytics-api

but I could not solve the problem

it is as if something was missing, google-play service is integrated because I'm using it for in-app purchase, but I do not understand why Android studio does not want to recognize google analytics.

add a photo for clarity: enter image description here

project structure:

enter image description here

EDIT 2

android:value in this meta-data

<meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version"/>

where @integer/google_play_services_version is 4132500

I checked the sdk and I have no updates to be done in Extras

Community
  • 1
  • 1
Ilario
  • 5,979
  • 2
  • 32
  • 46

5 Answers5

3

I would guess that you have an old version of Google Play Services in your app.

My suspicion comes from the fact that the classes you can see, such as GoogleApiClient, GoogleAuthUtil, GooglePlayServicesNotAvailableException, &c have been present in Play Services from the very first versions (that I have used, at least) while GoogleAnalytics was added somewhat later, at version 4.3

Google Play Services for Froyo is stuck at version 3.2.65 and doesn't include it, for example.

As the first step, please build your app and check the version number under <project>\<module>\build\intermediates\exploded-aar\com.google.android.gms\play-services. When using the (current) latest version, it should be 6.1.71, or thereabouts.

If the version displayed there is lower than 4.3, then it won't have Google Analytics embeded inside, and you should check/update your SDK (particularly the Google Repository under extras)

AdMob was added in Google Play Services 4.2. So I would bet with some confidence that you have this one. :)

matiash
  • 54,791
  • 16
  • 125
  • 154
  • this is an excellent answer. I will check this and let you know – Ilario Nov 07 '14 at 09:56
  • @Ilario just to be sure, did you check the folder name beneath \\build\intermediates\exploded-aar\com.google.android.gms\play-services ? – matiash Nov 07 '14 at 12:53
  • ok, the last version is 4.1.32 now how can I upgrade?? in SDK manager I can't see any update to do. i use android studio 0.5.9 – Ilario Nov 10 '14 at 11:06
  • @Ilario You could try running `gradlew --refresh-dependencies`, but this should be automatic, so it's very strange. Also, is there any chance you could update Android Studio? (You're using a very old version, I don't know if that might be related but it doesn't hurt to check). – matiash Nov 10 '14 at 11:41
  • yeah i'm using very old version, and now I'm updating to 0.9.2 , and in fact on SDK manager i can find an update to Google Play services to rev. 21. i'll let you know – Ilario Nov 10 '14 at 11:44
  • update Android studio is always a problem, but after a while I managed to solve. thanks for putting me on the right track. – Ilario Nov 10 '14 at 14:33
  • @Ilario Glad that the issue is resolved, hope to have helped! – matiash Nov 10 '14 at 15:22
3

Try adding this line to build.gradle

 compile 'com.google.android.gms:play-services-analytics:7.5.0'
Bala Vishnu
  • 2,588
  • 23
  • 20
  • try `compile com.google.android.gms:play-services-analytics:8.4.0` to include only google analytics. Android has maximum number of methods limitation of 64K or so. That may be the cause of the problem. – Thupten Jan 17 '16 at 07:23
  • Why people too lazy to say "which build.gradle" ? Everyone knows there are 2 build.gradle, Project and module!!!. Please tell me, why do not you say which build.gradle? – Gürkan Çatak Sep 23 '16 at 11:15
1

You have just forgotten to add enums as like it has been described on google examples.

    public enum TrackerName {
    APP_TRACKER, // Tracker used only in this app.
    GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
    ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
  }
Anton Kashpor
  • 1,255
  • 2
  • 18
  • 34
  • the problem is that after i wrote this, i've problem with: GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); Android Studio not know what is GoogleAnalytics, but i already use Google Play Services in my app... – Ilario Nov 06 '14 at 10:58
0

If you are using Android Studio you must add Proguard to your gradle.build file's build types. Refer the links given below:-

https://developers.google.com/analytics/devguides/collection/android/v4/

http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Running-ProGuard

Pravinsingh Waghela
  • 2,516
  • 4
  • 32
  • 50
  • sorry but I don't understand.. I have already seen this link, and do not understand what does Proguard here. In this link I have not seen a reference to Proguard. I follow this link but the issue is the same, Android Studio don't fine GoogleAnalytics class – Ilario Nov 06 '14 at 15:39
  • I have edited my answer check the second link for more details on Proguard. Also have you Included the Google Analytics jar file to your libs folder? For more details follow the given link:- http://stackoverflow.com/questions/24782901/how-to-integrate-google-analytics-in-android-app – Pravinsingh Waghela Nov 07 '14 at 06:49
0

It seems that you are includinh the Google lib via Maven, have you tried to grab the project and the jar and include it as a dependency of your project ? Also, you are using an old version of Google play services (mine is 4452000, and already a few month old).

thib_rdr
  • 79
  • 8
  • i've post a photo where google play services is added as dependencies... or i don't understand something.. – Ilario Nov 07 '14 at 10:37