在Android 4.4及更低版本中实施Google Analytics 7.5.0(Play服务)崩溃

时间:2015-07-23 06:34:18

标签: android google-analytics google-play-services

我实施Google Analytics后,我的应用程序立即在Lollipop之前的设备上崩溃。

07-22 15:42:43.831: W/dalvikvm(1815): VFY: unable to resolve virtual method     16407: Lcom/google/android/gms/analytics/internal/zzg;.getApplicationContext    ()Landroid/content/Context;
07-22 15:42:43.831: D/dalvikvm(1815): VFY: replacing opcode 0x6e at 0x0003
07-22 15:42:43.831: I/dalvikvm(1815): Could not find method com.google.android.gms.internal.zzld.zzoQ, referenced from method  com.google.android.gms.analytics.internal.zzf.zzV
07-22 15:42:43.831: W/dalvikvm(1815): VFY: unable to resolve static method  27402: Lcom/google/android/gms/internal/zzld;.zzoQ ()Lcom/google/android/gms/internal/zzlb;
07-22 15:42:43.831: D/dalvikvm(1815): VFY: replacing opcode 0x71 at 0x000e
07-22 15:42:43.831: W/dalvikvm(1815): VFY: unable to find class referenced in signature (Lcom/google/android/gms/internal/zzlb;)
07-22 15:42:43.831: W/dalvikvm(1815): VFY: Ljava/lang/Object; is not instance of Lcom/google/android/gms/analytics/internal/zzd;
07-22 15:42:43.831: W/dalvikvm(1815): VFY: bad arg 1 (into Lcom/google/android/gms/analytics/internal/zzd;)
07-22 15:42:43.831: W/dalvikvm(1815): VFY:  rejecting call to Lcom/google/android/gms/analytics/internal/zzf;.zza (Lcom/google/android/gms/analytics/internal/zzd;)V
07-22 15:42:43.831: W/dalvikvm(1815): VFY:  rejecting opcode 0x70 at 0x0002
07-22 15:42:43.831: W/dalvikvm(1815): VFY:  rejected Lcom/google/android/gms/analytics/internal/zzf;.zzhT ()Lcom/google/android/gms/analytics/internal/zzv;
07-22 15:42:43.831: W/dalvikvm(1815): Verifier rejected class Lcom/google/android/gms/analytics/internal/zzf;
07-22 15:42:43.831: D/AndroidRuntime(1815): Shutting down VM
07-22 15:42:43.831: W/dalvikvm(1815): threadid=1: thread exiting with uncaught exception (group=0xb0ce1b20)
07-22 15:42:43.831: E/AndroidRuntime(1815): FATAL EXCEPTION: main
07-22 15:42:43.831: E/AndroidRuntime(1815): Process: ---,      PID: 1815
07-22 15:42:43.831: E/AndroidRuntime(1815): java.lang.VerifyError: com/google/android/gms/analytics/internal/zzf
07-22 15:42:43.831: E/AndroidRuntime(1815):     at com.google.android.gms.analytics.GoogleAnalytics.getInstance(Unknown Source)
07-22 15:42:43.831: E/AndroidRuntime(1815):     at com.x.x.x.onCreate(x.java:22)
07-22 15:42:43.831: E/AndroidRuntime(1815):     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
07-22 15:42:43.831: E/AndroidRuntime(1815):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4328)
07-22 15:42:43.831: E/AndroidRuntime(1815):     at android.app.ActivityThread.access$1500(ActivityThread.java:135)
07-22 15:42:43.831: E/AndroidRuntime(1815):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
07-22 15:42:43.831: E/AndroidRuntime(1815):     at android.os.Handler.dispatchMessage(Handler.java:102)
07-22 15:42:43.831: E/AndroidRuntime(1815):     at android.os.Looper.loop(Looper.java:136)
07-22 15:42:43.831: E/AndroidRuntime(1815):     at android.app.ActivityThread.main(ActivityThread.java:5001)
07-22 15:42:43.831: E/AndroidRuntime(1815):     at java.lang.reflect.Method.invokeNative(Native Method)
07-22 15:42:43.831: E/AndroidRuntime(1815):     at java.lang.reflect.Method.invoke(Method.java:515)
07-22 15:42:43.831: E/AndroidRuntime(1815):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-22 15:42:43.831: E/AndroidRuntime(1815):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-22 15:42:43.831: E/AndroidRuntime(1815):     at dalvik.system.NativeStart.main(Native Method)

My Gradle文件(在android块内):

compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "x.x.x"
    minSdkVersion 14
    targetSdkVersion 22
    versionCode 6
    versionName "0.5"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

我使用此版本的Google Play服务:

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

我已经在网上搜索了很多关于这个主题的内容,但找不到任何解决问题的方法。最接近的一个是关于SO的答案,不幸的是,这对我没有用:https://stackoverflow.com/a/31432568

2 个答案:

答案 0 :(得分:2)

尝试使用新的Android配置启用MultiDex,构建工具22.0.1有一个我在MultiDex上报告的错误(正如您在此处看到的那样:java.lang.VerifyError with API < 21)。

因此,在gradle中启用MultiDex并使用构建工具23 rc3:

compileSdkVersion 22
buildToolsVersion "23 rc3"

defaultConfig {
    applicationId "x.x.x"
    minSdkVersion 14
    targetSdkVersion 22
    versionCode 6
    versionName "0.5"
    multiDexEnabled = true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

将其导入您的依赖项(最新版本为1.0.1)

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:multidex:1.0.1'
}

并将其附加到您的应用程序中的基本上下文中:

public class MyApplication extends CustomLibraryApplication {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

或扩展MultiDexApplication:

public class MyApplication extends MultiDexApplication {

}

或者在清单中使用MultiDexApplication。

答案 1 :(得分:1)

您似乎必须导入{{1}}。我首先删除了proguard,然后观察了异常,这与我在link中发现的内容有关。请仔细阅读以获得详尽的答案。