使用推送通知时出错,java.lang.IncompatibleClassChangeError:android.support.v4.content.ContextCompat错误

时间:2016-09-16 07:03:32

标签: android android-studio firebase push-notification google-cloud-messaging

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

尝试获取令牌时的日志输出

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)

我正在我的应用中实施推送通知,但是当我调用GcmIntentService时,我收到了我已经在日志输出中发布的错误。我也试过使用FCM,但遇到了同样的问题。如果有人实现了这一点,那么请帮忙。提前谢谢。

1 个答案:

答案 0 :(得分:0)

**指得到了我的问题的答案错误是因为使用了播放服务

  

9.0.0

     

但是当我们将游戏服务更新到9.4.0并且与firebase相同时   依赖。我的gradle中的主要问题是apply plugin:   'com.google.gms.google-services'不会成为最重要的   在依赖之后会出现在底部。我不知道为什么会这样   工作正常,我的令牌和上下文紧凑问题也得到了解决。**

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

它应该是这样的。 :)