ANDROID - FATAL EXCEPTION: IntentService[] [..] java.lang.IncompatibleClassChangeError [..]

ぐ巨炮叔叔 提交于 2019-12-12 04:25:55

问题


I try send notification for my application with Google Cloud Message.

I created a new project and I implemented the code and this work fine. but when i try implement in my application, the application show this error message:

ERROR MESSAGE:

08-07 14:48:57.735 324-1057/br.com.pkg.project E/AndroidRuntime: FATAL EXCEPTION: IntentService[]
                                                                     Process: br.com.pkg.project, PID: 324
                                                                     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 'com.google.android.gms.iid.zzd' appears in /data/data/br.com.auttar.auttarmobile/files/instant-run/dex/slice-com.google.android.gms-play-services-gcm-8.3.0_22bae0a13164f788de113fe2ab4647903157f661-classes.dex)
                                                                         at com.google.android.gms.iid.zzd.zzdL(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 br.com.pkg.project.tools.util.gcm.GCMRegistrationIntentService.registerGCM(GCMRegistrationIntentService.java:37)
                                                                         at br.com.pkg.project.tools.util.gcm.GCMRegistrationIntentService.onHandleIntent(GCMRegistrationIntentService.java:29)
                                                                         at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                         at android.os.HandlerThread.run(HandlerThread.java:61)

I have this method in GCMRegistrationIntentService.class

private void registerGCM() {
    Intent registrationComplete = null;
    String token = null;

    try{
        InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
        token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

        Log.v("GCMRegIntentService","TOKEN: "+token);

        registrationComplete = new Intent(REGISTRATION_SUCESS);
        registrationComplete.putExtra("token",token);
    } catch (Exception e) {
        Log.v("GCMRegIntentService","ERRO AO REGISTRAR O TOKEN");
        registrationComplete = new Intent(REGISTRATION_ERROR);
    }
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}

The error it ocorred in this line:

 InstanceID instanceID = InstanceID.getInstance(getApplicationContext());

Manifest.xml permission

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<!-- uses-permission android:name="android.permission.READ_CONTACTS" / -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<permission android:name="br.com.pkg.project.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="br.com.pkg.project.permission.C2D_MESSAGE" />

Manifest.xml receiver

enter code here        <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
            <!-- PODE SER AQUI -->
            <category android:name="br.com.pkg.project"/>
        </intent-filter>
    </receiver>
    <service android:name=".tools.util.gcm.GCMPushReceiverService" android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
        </intent-filter>
    </service>
    <service android:name=".tools.util.gcm.GCMRegistrationIntentService" android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.gms.iid.InstanceID"/>
        </intent-filter>
    </service>

build.Gradle

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

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "br.com.pkg.project"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
    }
}



dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:+'
    //compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.google.code.gson:gson:2.2.4'
    //compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.google.android.gms:play-services:8.3.0'
    // http://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
    //compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.4'
    //compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
    compile 'com.jjoe64:graphview:4.0.1'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
    //compile 'org.springframework.android:spring-android-rest-template:2.0.0.M1'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.3.2'
    compile files('libs/spring-android-rest-template-1.0.1.RELEASE.jar')

}

build.Gradle

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.google.gms:google-services:1.5.0-beta2'
        classpath 'com.android.tools.build:gradle:2.0.0-alpha6'

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

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I have Consulted other similar questions in the StackOverFlow, but not one solved my problem.

Can anybody help me, please ?

SOLVED

I include this dependences

 configurations.all {
    resolutionStrategy {
        //force 'com.android.support:design:23.4.0'
        force 'com.android.support:support-v4:23.4.0'
        force 'com.android.support:appcompat-v7:23.4.0'
    }
}

Studies by me, what was found : GCM no work with support version >=24

Correct me if I'm wrong , but it worked

Thank for all

来源:https://stackoverflow.com/questions/38817093/android-fatal-exception-intentservice-java-lang-incompatibleclasschang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!