需要帮助处理由 java.lang.IncompatibleClassChangeError 引起的致命异常 [英] Need help dealing with a Fatal Exception caused by java.lang.IncompatibleClassChangeError

查看:71
本文介绍了需要帮助处理由 java.lang.IncompatibleClassChangeError 引起的致命异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我昨天在 Android Studio 中遇到了这个我以前从未见过的错误,这是由过去 3 个月内未触及的一段代码引起的.这来自用于注册推送通知的代码,本周早些时候工作正常,但现在导致此错误:

So, I ran into this error just yesterday in Android Studio that I've never seen before, caused by a piece of code that hasn't been touched over the past 3 months. This came from the code being used to register for push notifications and was working fine earlier this week, but now it results in this error:

05-20 10:37:02.064 22471-22681/com.appname E/AndroidRuntime: FATAL EXCEPTION: IntentService[RegIntentService]
                                                               Process: com.appname, PID: 22471
                                                               java.lang.IncompatibleClassChangeError: The method 'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)' was expected to be of type virtual but instead was found to be of type direct (declaration of 'java.lang.reflect.ArtMethod' appears in /system/framework/core-libart.jar)
                                                                   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.appname.services.RegistrationIntentService.onHandleIntent(RegistrationIntentService.java:32)
                                                                   at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
                                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                   at android.os.Looper.loop(Looper.java:135)
                                                                   at android.os.HandlerThread.run(HandlerThread.java:61)

这是我的 RegistrationIntentService 类:

Here is my RegistrationIntentService class:

package com.appname.services;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.android.gms.iid.InstanceID;
import com.appname.MainSharedPreferences;
import com.appname.R;
import java.io.IOException;

public class RegistrationIntentService extends IntentService {

    private static final String TAG = "RegIntentService";

    public RegistrationIntentService() {
        super(TAG);
    }
    public static void startService(final Context context) {
        final Intent intent = new Intent(context, RegistrationIntentService.class);
        context.startService(intent); //HERE is the line that is causing the crash
    }

    @Override
    public void onHandleIntent(Intent intent) {
        InstanceID instanceID = InstanceID.getInstance(this);
        try {
            String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId) , GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
            MainSharedPreferences.saveGCMInstanceToken(token, getApplicationContext());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

这是从我的 MainActivity 类调用上述类的代码行:

This is the line of code that is calling the above class from my MainActivity class:

RegistrationIntentService.startService(getApplicationContext());

关于我的 MainActivity 的一些信息,如果有帮助的话...

Some info on my MainActivity if it helps...

public class MainActivity extends SocialActivity implements SeekBar.OnSeekBarChangeListener

public abstract class SocialActivity extends AppCompatActivity implements GraphRequest.GraphJSONObjectCallback

我试过跳回几个较旧的提交,但遇到了同样的错误.这让我相信我的 Android Studio 或 java 版本可能有问题.我更新了我的java版本并重新安装了Android Studio,仍然是同样的错误.也用旧版本在单独的电脑上试过,还是一样的错误.

I've tried jumping back to several older commits, but got the same error. This led me to believe that maybe there was problem with my Android Studio or java version. I updated my java version and reinstalled Android Studio, still the same error. Also tried on a separate computer with older versions, still the same error.

我什至尝试根据本指南从 GCM 迁移到 Firebase 并最终再次出现同样的错误.

I even tried migrating from GCM to Firebase according to this guide and ended up getting the same error again.

我可以注释掉导致应用崩溃的那一行,它会正常运行,但是我不再收到通知.

I can comment out the line that crashes the app and it will run fine, but then I no longer receive notifications.

对此问题的任何帮助或建议将不胜感激!

Any help or advice on this matter would be much appreciated!

这里还有我的相关编译/类路径语句......

Here are my relevant compile/classpath statements as well...

在 appname build.gradle 中:

In the appname build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    repositories { mavenCentral() }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

在应用 build.gradle 中:

In the app build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    //...
}

allprojects {
    //...
}

android {
   //...
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.code.gson:gson:2.5'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:recyclerview-v7:+'
    compile "com.google.firebase:firebase-messaging:9.0.0"
    //...
}

apply plugin: 'com.google.gms.google-services'

推荐答案

5 月 27 日更新:

我们刚刚发布了一个更新(版本 9.0.1)来修复我在第一次编辑中提到的不兼容性.
请更新您的依赖项,如果这仍然是一个问题,请告诉我们.

we just released an update (version 9.0.1) to fix the incompatibility I mentioned in my first edit.
Please update your dependencies and let us know if this is still an issue.

谢谢!

5 月 20 日的原始答案:

您遇到的问题是由于
play-services/firebase sdk v9.0.0com.android.support:appcompat-v7 >= 24
(android-N sdk 发布的版本)

The issue you are experiencing is due to an incompatibility between
play-services / firebase sdk v9.0.0 and com.android.support:appcompat-v7 >= 24
(the version released with android-N sdk)

您应该能够通过定位支持库的早期版本来修复它.喜欢:

You should be able to fix it by targeting an earlier version of the support library. Like:

compile 'com.android.support:appcompat-v7:23.4.0'

这篇关于需要帮助处理由 java.lang.IncompatibleClassChangeError 引起的致命异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆