使用GoogleAnalytics和proguard

时间:2016-03-21 12:22:11

标签: google-analytics proguard

我在我的应用程序中使用Google Analytics和proguard。 应用程序工作正常,没有启用proguard。 但是当我创建已启用Proguard和GoogleAnalytics的已签名Apk时,我会收到以下错误。

我搜索了很多但无法找到解决方案。请帮忙

GoogleAnalytics类:

public class MyApplication extends Application {
    public static final String TAG = MyApplication.class
            .getSimpleName();

    private static MyApplication mInstance;

    public static synchronized MyApplication getInstance() {
        return mInstance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;

        AnalyticsTrackers.initialize(this);
        AnalyticsTrackers.getInstance().get(AnalyticsTrackers.Target.APP);


    }

    public synchronized Tracker getGoogleAnalyticsTracker() {
        AnalyticsTrackers analyticsTrackers = AnalyticsTrackers.getInstance();

        return analyticsTrackers.get(AnalyticsTrackers.Target.APP);
    }

    /***
     * Tracking screen view
     *
     * @param screenName screen name to be displayed on GA dashboard
     */
    public void trackScreenView(String screenName) {
        Tracker t = getGoogleAnalyticsTracker();

        // Set screen name.
        t.setScreenName(screenName);

        // Send a screen view.
        t.send(new HitBuilders.ScreenViewBuilder().build());

        GoogleAnalytics.getInstance(this).dispatchLocalHits();
    }

    /***
     * Tracking exception
     *
     * @param e exception to be tracked
     */
    public void trackException(Exception e) {
        if (e != null) {
            Tracker t = getGoogleAnalyticsTracker();

            t.send(new HitBuilders.ExceptionBuilder()
                            .setDescription(
                                    new StandardExceptionParser(this, null)
                                            .getDescription(Thread.currentThread().getName(), e))
                            .setFatal(false)
                            .build()
            );
        }
    }

    /***
     * Tracking event
     *
     * @param category event category
     * @param action   action of the event
     * @param label    label
     */
    public void trackEvent(String category, String action, String label) {
        Tracker t = getGoogleAnalyticsTracker();

        // Build and send an Event.
        t.send(new HitBuilders.EventBuilder().setCategory(category).setAction(action).setLabel(label).build());
    }
  

java.lang.NoSuchMethodError:没有接口方法j()我在类中   Landroid /内容/ RES / XmlResourceParser;或者它的超级课程   (声明' android.content.res.XmlResourceParser'出现在   /system/framework/framework.jar)                                                          在com.google.android.gms.analytics.internal.zzp.zza(未知来源)                                                          在com.google.android.gms.analytics.internal.zzp.zzS(未知来源)                                                          在com.google.android.gms.analytics.GoogleAnalytics.newTracker(未知   资源)                                                          在com.xxxx.xxx.googleAnalytics.a.a(未知来源)                                                          在com.xxx.xxx.googleAnalytics.MyApplication.onCreate(未知来源)                                                          在android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1017)

2 个答案:

答案 0 :(得分:3)

出于任何未知原因,我们不得不添加:

-keep class org.xmlpull.v1.** { *;}
-dontwarn org.xmlpull.v1.**

答案 1 :(得分:1)

从您的错误日志中,似乎找不到接口j()。

但如果这是谷歌图书馆的错误,这将有助于你

保持com.google类。 {*;} **

-keepclassmembers com.google。 {*;} **

如果您仍然收到错误,请使用此

-dontwarn com.google