如何在Android应用中使用超过65K方法的Google Analytics

时间:2015-12-04 18:14:46

标签: android google-analytics

Building Apps with over 65K methods要求清单中包含以下内容:

  <application
        ...
        android:name="AnalyticsApplication">
        ...
  </application>

Using Google Analytics需要清单中的以下内容:

{{1}}

这两者如何协调?

2 个答案:

答案 0 :(得分:4)

您是否在应用程序类中尝试过MultiDex.install

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

在不更改清单中的应用名称的情况下,它可以正常使用。 有关详细信息,请参阅How to enable multidexing with the new Android Multidex support library

编辑:

您可以创建一个扩展Application

的新类
public class AnalyticsApplication extends Application {
  private Tracker mTracker;

  @Override
  protected void attachBaseContext(Context base) {
      super.attachBaseContext(base);
      MultiDex.install(this);
  }

  /**
   * Gets the default {@link Tracker} for this {@link Application}.
   * @return tracker
   */
  synchronized public Tracker getDefaultTracker() {
    if (mTracker == null) {
      GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
      // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
      mTracker = analytics.newTracker(R.xml.global_tracker);
    }
    return mTracker;
  }
}

然后在你的清单中:

<application
    ...
    android:name="AnalyticsApplication">
    ...
</application>

答案 1 :(得分:0)

1)在multidex

中启用build.gradle
android {
    defaultConfig {
        // your stuff
        multiDexEnabled true
    }
}

2)需要继承Application并添加此

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}