Android GoogleAnalytics getInstance

2019-01-17 20:21发布

in Application class, in create method I call GoogleAnalytics.getInstance(this) and application just freezes...on any device Worked fine with google play services 6.1, now it's 6.5 and I have no idea what could cause this.... Any ideas?

public class BaseApplication extends Application {

    private static Tracker mTracker;
    private MyProfile mMyProfile;

    public BaseApplication() {
        super();
    }

    private void initTracker() {
        if (mTracker == null) {
            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
            mTracker = analytics.newTracker(R.xml.global_tracker);
            mTracker.enableAdvertisingIdCollection(true);
        }
    }

`...

Gradle 
dependencies {
    compile project(':IMFramework')
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.google.android.gms:play-services-base:6.5.87'
    compile 'com.google.android.gms:play-services-maps:6.5.87'
}

5条回答
做自己的国王
2楼-- · 2019-01-17 20:35

GoogleAnalytics.getInstance() deadlocks while trying to parse the xml tracker definition.

The issue is fixed in Google Play Services 7.0 that was released March 19, 2015. Upgrading to 7.0 will fix the deadlock. http://developer.android.com/google/play-services/index.html

If you must use Play Services 6.5, you can workaround the deadlock by initializing the tracker from code instead of xml resource:

public static final String TRACKER_ID="UA-xxx";
...
mTracker = analytics.newTracker(TRACKER_ID);
// Configure mTracker using the tracker provided methods
查看更多
3楼-- · 2019-01-17 20:40

Worked fine with google play services 6.1

Good, I did rollback to 6.1.+ I think it some internal error that will be fixed in an next update.

Upd

It fixed in 7.0

查看更多
Fickle 薄情
4楼-- · 2019-01-17 20:43

removing this line from the manifest solved the problem for me:

meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="@xml/global_tracker"

查看更多
不美不萌又怎样
5楼-- · 2019-01-17 20:46

I got this error:

java.lang.NoSuchMethodError: No static method zzz(Ljava/lang/Object;)Ljava/lang/Object; in class Lcom/google/android/gms/common/internal/zzaa; or its super classes (declaration of 'com.google.android.gms.common.internal.zzaa' appears in /data/data/com.crave.iapdemo/files/instant-run/dex/slice-com.google.android.gms-play-services-basement-10.0.1_b9da1447b99cc6cbc2fa601fb84d0418780bfa55-classes.dex)
                                                                       at com.google.android.gms.analytics.internal.zzf.zzX(Unknown Source)
                                                                       at com.google.android.gms.analytics.GoogleAnalytics.getInstance(Unknown Source)

in this line:

GoogleAnalytics.getInstance(this)

The solution for me was upgrading this:

dependencies {
    // play services
    compile 'com.google.android.gms:play-services-gcm:9.0.0'
    compile 'com.google.android.gms:play-services-analytics:9.0.0'
}

into:

dependencies {
    // play services
    compile 'com.google.android.gms:play-services-gcm:10.0.1'
    compile 'com.google.android.gms:play-services-analytics:10.0.1'
}
查看更多
Ridiculous、
6楼-- · 2019-01-17 20:46

Just in case the other fixes mentioned here don't work for you, here's what worked for me:

In build.gradle I changed...

compile 'com.google.android.gms:play-services:6.5.87'

...to...

compile 'com.google.android.gms:play-services-base:6.5.87'

...and it stopped hanging. I don't know why.

查看更多
登录 后发表回答