IncompatibleClassChangeError引起的致

IncompatibleClassChangeError引起的致

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

问题描述

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

  05-20 10:37:02.064 22471-22681 / com.appname E / AndroidRuntime:FATAL EXCEPTION:IntentService [RegIntentService] 
过程:com.appname,PID:22471
java.lang.IncompatibleClassChangeError :'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)'方法预计是虚拟类型,但是被发现是直接类型的(声明'java。 lang.reflect.ArtMethod'出现在/system/framework/core-libart.jar)
在com.google.android.gms.iid.zzd.zzeb(未知来源)
在com.google。安卓.gms.iid.zzd。< init>(未知来源)
在com.google.android.gms.iid.zzd。< init>(未知来源)
在com.google.android .gms.iid.InstanceID.zza(未知来源)
在com.google.android.gms.iid.InstanceID.getInstance(未知来源)
在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.loo在android.os.HandlerThread.run(HandlerThread.java:61)
b $ b

这是我的RegistrationIntentService类:

  package com.appname.services; 

导入android.app.IntentService;
导入android.content.Context;
导入android.content.Intent;
导入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是引起崩溃的行

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


$ / code>

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

  RegistrationIntentService.startService(getApplicationContext()); 

我的MainActivity上有一些信息,如果有帮助...

  public class MainActivity extends SocialActivity implements SeekBar.OnSeekBarChangeListener 

public abstract class SocialActivity extends AppCompatActivity implements GraphRequest.GraphJSONObjectCallback

我尝试跳回几个较旧的提交,但得到相同的错误。这让我相信,也许我的Android Studio或Java版本存在问题。我更新了我的Java版本并重新安装了Android Studio,仍然是同样的错误。



我甚至试着根据,并最终再次得到同样的错误。



我可以注释掉崩溃应用程序的行,它会正常运行,但我不再收到通知。



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

编辑:下面是我的相关编译/类路径语句以及...

在appname build.gradle中:

  buildscript {
repositories {
jcenter()
}
存储库{mavenCentral()}
依赖关系{
classpath'com.android.tools.build:gradle:2.1.0'
classpath'com.google.gms: google-services:3.0.0'

//注意:不要放置你的appl依赖关系在这里;它们属于单个模块build.gradle文件
//

$ b code


在app build.gradle中:

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

repositories {
// ...
}

allprojects {
// .. 。
}

android {
// ...
}

依赖项{
编译fileTree(dir:' libs',包括:['* .jar'])
testCompile'junit:junit:4.12'
compile'c​​om.android.support:appcompat-v7:23.4.0'
compile 'com.google.code.gson:gson:2.5'
compile'c​​om.android.support:design:23.4.0'
compile'c​​om.android.support:recyclerview-v7:+'
compilecom.google.firebase:firebase-messaging:9.0.0
// ...
}

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


解决方案

update may 27 :我们刚刚发布了一个更新( version 9.0.1 )来解决我提到的不兼容问题在我的第一次编辑。
请更新您的依赖关系,并让我们知道这是否仍然是一个问题。



谢谢!




原始答案5月20日:

您遇到的问题是由于
play-services / firebase sdk v9.0.0
com.android.support:appcompat-v7> = 24

(使用android-N sdk发布的版本)



您应该可以通过定位早期版本的支持库来修复它。像:

  compile'c​​om.android.support:appcompat-v7:23.4.0'


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)

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();
        }
    }

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

RegistrationIntentService.startService(getApplicationContext());

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

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.

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!

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

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
    }
}

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'
解决方案

update may 27:

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.

Thanks!


original answer May 20:

The issue you are experiencing is due to an incompatibility between
play-services / firebase sdk v9.0.0 andcom.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引起的致命异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 07:31