Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio cannot resolve symbol GoogleAnalytics v4

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

like image 830
Ilario Avatar asked Mar 19 '23 06:03

Ilario


2 Answers

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. :)

like image 66
matiash Avatar answered Apr 01 '23 06:04

matiash


Try adding this line to build.gradle

 compile 'com.google.android.gms:play-services-analytics:7.5.0'
like image 23
Bala Vishnu Avatar answered Apr 01 '23 06:04

Bala Vishnu