Android Studio cannot resolve symbol GoogleAnalytics v4

ぐ巨炮叔叔 提交于 2019-12-10 07:07:50

问题


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:

project structure:

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


回答1:


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




回答2:


Try adding this line to build.gradle

 compile 'com.google.android.gms:play-services-analytics:7.5.0'



回答3:


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.
  }



回答4:


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




回答5:


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



来源:https://stackoverflow.com/questions/26254017/android-studio-cannot-resolve-symbol-googleanalytics-v4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!