GCM注销,导致应用程序崩溃


问题内容

我已经在我的应用中实现了GCM通知。我现在尝试在用户注销时注销该应用程序。我正在使用以下代码。执行此代码时,它将导致应用程序崩溃,并显示以下logcat:

java.lang.IllegalAccessError: Method 'void android.support.v4.content.ContextCompat.<init>()' is inaccessible to class 'com.google.android.gms.iid.zzd' (declaration of 'com.google.android.gms.iid.zzd' appears in /data/app/com.example.packagename-1/base.apk)
    at com.google.android.gms.iid.zzd.zzeb(Unknown Source)
    at com.google.android.gms.iid.zzd.<init>(Unknown Source)
    at com.google.android.gms.iid.zzd.<init>(Unknown Source)
    at com.google.android.gms.iid.InstanceID.zza(Unknown Source)
    at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source)
    at com.zaryans.updatedepoultry.WelcomeActivity$11.onItemClick(WelcomeActivity.java:469)
    at android.widget.AdapterView.performItemClick(AdapterView.java:310)
    at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3066)
    at android.widget.AbsListView$3.run(AbsListView.java:3903)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

这是代码:

InstanceID instanceID = InstanceID.getInstance(WelcomeActivity.this);
try {
   instanceID.deleteInstanceID();
   Utility.logCatMsg("Logged Out Success!!!");
} catch (IOException e) {
   Utility.logCatMsg("Exception while logging out: "+e.getMessage());
   e.printStackTrace();
}

问题答案:

将支持库更新为25.0.0后,我遇到了同样的问题。对我来说,更新下面的库之后,在应用程序gradle文件中,问题消失了。

compile("com.google.android.gms:play-services-location:9.6.1")
compile("com.google.android.gms:play-services-maps:9.6.1")
compile("com.google.android.gms:play-services-gcm:9.6.1")