com.google.android.gms.common.internal.safe parcel.safe parcelable未找到。

52

我正在尝试使用FCM为我的应用添加通知服务,使用的教程在https://www.simplifiedcoding.net/firebase-cloud-messaging-android/上。一切都已完成并正常工作,例如获取令牌等等。但是现在,在创建消息处理程序后,我开始收到错误:

Error:(22, 26) error: cannot access AbstractSafeParcelable
class file for com.google.android.gms.common.internal.safeparcel.AbstractSafeParcelable not found

构建失败,请指导。Gradle 代码如下:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }

    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'


repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven {
        url "https://s3-ap-southeast-1.amazonaws.com/godel-release/godel/"
    }
}


android {
    compileSdkVersion 25
    buildToolsVersion "24.0.3"
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "jss.smartapp"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {

            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }


    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
    }
}

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'
    })
    testCompile 'junit:junit:4.12'
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')
//Apache IO
    compile files('libs/commons-io-2.5.jar')
    compile 'com.android.support:design:25.0.0'
    compile 'com.android.support:appcompat-v7:25.0.0'
//Crashlytics
    compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
        transitive = true;
    }
    //Dropbox
    compile 'com.dropbox.core:dropbox-core-sdk:2.0.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
//FTP
    compile files('libs/ftp4j-1.7.2.jar')
//Http
    compile 'com.squareup.okhttp3:okhttp:3.4.2'
//Instamojo
    compile 'com.instamojo:android-sdk:+'
//Material Design Didalogs
    compile 'com.afollestad.material-dialogs:commons:0.9.1.0'
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
//GSON
    compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
    compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
//multidex dependency
    compile 'com.android.support:multidex:1.0.1'
    //box dependencies
    compile 'com.box:box-java-sdk:2.1.1'
    compile 'com.box:box-android-sdk:3.0.2'
//google drive dependency
    compile 'com.google.android.gms:play-services-drive:10.0.1'
    //one drive dependency
    compile('com.onedrive.sdk:onedrive-sdk-android:1.2+') {
        transitive = false
    }
    compile('com.microsoft.services.msa:msa-auth:0.8.+')
    compile('com.microsoft.aad:adal:1.1.+')

    //justify test
    compile 'com.github.bluejamesbond:textjustify-android:2.1.6'

    //image downnloader
    /*compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'*/
//Glide Image downloading
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.android.support:support-v4:25.1.0'
    compile 'com.google.firebase:firebase-messaging:9.2.1'

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

我猜测是Multidex引起的。因为使用Multidex时,所有类不在同一个dex中,所以可能会发生这种情况。 - Fatima
6个回答

154

在你的Gradle文件中,所有的google-play-service和firebase版本应该使用相同的版本号

由于你正在使用:

 compile 'com.google.android.gms:play-services-drive:10.0.1'

你应该使用:

compile 'com.google.firebase:firebase-messaging:10.0.1' // 而不是 9.2.1


感谢 @GuillaumeAgis - Jordi Gámez
干得好。谢谢,伙计...!! - Harsh Patel
2
在Ionic 2中,我遇到了同样的问题,应该在哪里运行编译命令? - RSA

19

您必须将所有Google Play服务应用程序保持在同一版本:

compile 'com.google.android.gms:play-services:11.0.1'
compile 'com.google.android.gms:play-services-maps:11.0.1'
compile 'com.google.firebase:firebase-core:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'

有没有想过为什么文档使用com.google.android.gms:play-services-base:11.0.4?感谢您挽救了我的理智! - Wainage
耶!非常感谢你。它对我有效。再次感谢。 - Nikunj Kakadiya

11

这是一个 Android Studio 的 bug,它没有像对待 play-services* 库一样提供自动升级 Firebase 库的选项。

自动更新

compile 'com.google.android.gms:play-services-drive:10.0.1'

无自动更新(需要手动将版本更新为与Play Services *相同)

compile 'com.google.firebase:firebase-messaging:10.0.1'

3

可以使用以下内容:

dependencies {
    compile 'com.google.android.gms:play-services:11.0.1'
    compile 'com.google.firebase:firebase-core:11.0.1'
    compile 'com.google.firebase:firebase-messaging:11.0.1'
}
apply plugin: 'com.google.gms.google-services'

确保将apply plugin放在dependencies之下。

2

确保您的Google服务版本与Firebase版本相匹配。目前的编译“com.google.android.gms:play-services-drive:10.0.1”与编译“com.google.firebase:firebase-messaging:9.2.1”不匹配。 您需要将“com.google.firebase:firebase-messaging:9.2.1”更改为“com.google.firebase:firebase-messaging:10.0.1”,以使版本匹配。


0

最终救了我:

在Android Studio中,切换到项目视图而不是Android视图。 删除.gradle文件夹和gradle.properties文件。 清理项目。 再次同步gradle。

我不知道为什么这样做可以解决问题。仅删除.gradle文件夹并不能解决问题,而新生成的gradle.properties与旧的完全相同!但我的问题已经解决了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接