错误使用推 Notification ,java.lang.IncompatibleClassChangeError: android.support.v4.content.ContextCompat 错误

发布时间: 2016/10/10 22:31:38
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我的 app.gradle

 apply plugin: 'com.android.application'
    apply plugin: 'android-apt'
    apply plugin: 'com.google.gms.google-services'
    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.2"
        defaultConfig {
            applicationId "com.mss.plix"
            minSdkVersion 16
            targetSdkVersion 24
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            multiDexEnabled true
        }
        //====================Add below two line=============
        dexOptions {
            javaMaxHeapSize "4g" //specify the heap size for the dex process
            preDexLibraries = false //delete the already predexed libraries
        }

        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    ext {
        permissionsDispatcherVersion = '2.1.2'
    }
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
        compile 'de.hdodenhof:circleimageview:2.0.0'
        compile 'com.jakewharton:butterknife:7.0.1'
        testCompile 'junit:junit:4.12'
        compile 'de.hdodenhof:circleimageview:2.0.0'
        compile 'com.isseiaoki:simplecropview:1.1.4'
        compile 'com.github.hotchemi:permissionsdispatcher:2.1.3'
        compile 'com.github.aakira:expandable-layout:1.4.1@aar'
        compile 'com.github.hotchemi:permissionsdispatcher:2.1.3'
        apt "com.github.hotchemi:permissionsdispatcher-processor:2.1.3"
        compile project(':library')
       compile 'com.android.support:appcompat-v7:24.2.0'
       compile 'com.android.support:design:24.2.0'
        compile 'com.android.support:recyclerview-v7:24.2.0'
        compile 'com.android.support:cardview-v7:24.2.0'
        compile 'com.google.code.gson:gson:2.6.2'
        compile 'com.squareup.retrofit2:retrofit:2.0.2'
        compile 'com.squareup.retrofit2:converter-gson:2.0.2'
        compile 'com.squareup.okhttp:okhttp:2.5.0'
        compile 'com.android.support:multidex:1.0.1'
        compile 'com.google.android.gms:play-services:9.0.0'
        compile 'com.android.support:support-v4:24.2.1'


    }



    repositories {
        jcenter()
    }

我项目 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.2.0-rc2'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        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
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

Log 输出时试图获取标记

E/UncaughtException: java.lang.IncompatibleClassChangeError: android.support.v4.content.ContextCompat
                                                          at com.google.android.gms.iid.zzd.zzeC(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.mss.plix.Notifications.GCMRegistrationIntentService.registerGCM(GCMRegistrationIntentService.java:43)
                                                          at com.mss.plix.Notifications.GCMRegistrationIntentService.onHandleIntent(GCMRegistrationIntentService.java:30)
                                                          at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                          at android.os.Looper.loop(Looper.java:136)
                                                          at android.os.HandlerThread.run(HandlerThread.java:61)

我执行推 notification 在我的应用程序,但当我打电话 GcmIntentService ,我收到我已经发布中的错误我 log 输出。我也尝试过使用 FCM 但得到了同样的问题。如果任何人实施了这,然后请帮助。在此先感谢。

解决方法 1:

* * > 了发生此错误是使用播放我问题的答案service

9.0.0

但当我们更新播放 service 9.4.0 和火力点一样依赖项和我 gradle 的主要问题是适用插件: ' com.google.gms.google-服务不会的 gradle 后依赖项会在底部顶部。我不知道为什么这工作正常且我令牌和 context 紧凑的问题也得到了 resolved.* *

apply plugin: 'com.android.application'
    apply plugin: 'android-apt'

    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.2"
        defaultConfig {
            applicationId "com.mss.plix"
            minSdkVersion 16
            targetSdkVersion 24
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            multiDexEnabled true
        }
        //====================Add below two line=============
        dexOptions {
            javaMaxHeapSize "4g" //specify the heap size for the dex process
            preDexLibraries = false //delete the already predexed libraries
        }

        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    ext {
        permissionsDispatcherVersion = '2.1.2'
    }
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
        compile 'de.hdodenhof:circleimageview:2.0.0'
        compile 'com.jakewharton:butterknife:7.0.1'
        testCompile 'junit:junit:4.12'
        compile 'de.hdodenhof:circleimageview:2.0.0'
        compile 'com.isseiaoki:simplecropview:1.1.4'
        compile 'com.github.hotchemi:permissionsdispatcher:2.1.3'
        compile 'com.github.aakira:expandable-layout:1.4.1@aar'
        compile 'com.github.hotchemi:permissionsdispatcher:2.1.3'
        apt "com.github.hotchemi:permissionsdispatcher-processor:2.1.3"
        compile project(':library')
       compile 'com.android.support:appcompat-v7:24.2.0'
       compile 'com.android.support:design:24.2.0'
        compile 'com.android.support:recyclerview-v7:24.2.0'
        compile 'com.android.support:cardview-v7:24.2.0'
        compile 'com.google.code.gson:gson:2.6.2'
        compile 'com.squareup.retrofit2:retrofit:2.0.2'
        compile 'com.squareup.retrofit2:converter-gson:2.0.2'
        compile 'com.squareup.okhttp:okhttp:2.5.0'
        compile 'com.android.support:multidex:1.0.1'
        compile 'com.google.android.gms:play-services:9.0.0'
        compile 'com.android.support:support-v4:24.2.1'


    }

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

    repositories {
        jcenter()
    }

它应该是这样。:)

赞助商