Google Analytics blocks Android App

前端 未结 3 1476
孤城傲影
孤城傲影 2020-12-01 06:33

I use Google Analytics in my Android App and it works well. After updating the SDK (google play service) to the current version (6587000) the app hangs up at startup at foll

相关标签:
3条回答
  • 2020-12-01 06:47

    I had the same ANR issue every time I was calling GoogleAnalytics.getInstance(this). The problem seems to appear when the Google Play Services version in the app is not matching the one installed on the device.

    I solved this by checking if Google Play Services is "available":

    if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        // Create your tracker...
    }
    
    0 讨论(0)
  • 2020-12-01 06:48

    This is a know bug in Google Play Services 6.5.

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

    0 讨论(0)
  • 2020-12-01 06:53

    i had similar i removed the below code and application runs..

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

    and add following code for getTracker class... build the GoogleAnalytics using java code rather than XML approch

    synchronized Tracker getTracker(TrackerName trackerId) {
            Log.d(TAG, "getTracker()");
            if (!mTrackers.containsKey(trackerId)) {
                GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
    
                // Global GA Settings
                // <!-- Google Analytics SDK V4 BUG20141213 Using a GA global xml freezes the app! Do config by coding. -->
                analytics.setDryRun(false);
    
                analytics.getLogger().setLogLevel(Logger.LogLevel.INFO);
                //analytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
    
                // Create a new tracker
                Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(R.xml.ga_tracker_config) : null;
                if (t != null) {
                    t.enableAdvertisingIdCollection(true);
                }
                mTrackers.put(trackerId, t);
            }
            return mTrackers.get(trackerId);
        }
    
    0 讨论(0)
提交回复
热议问题