2016-12-31 88 views
45

我正在嘗試使用FCM向我的應用程序添加通知服務,並在https://www.simplifiedcoding.net/firebase-cloud-messaging-android/上給出了教程 所有操作都已完成,並且像獲取令牌等一樣工作。但現在創建消息處理程序後,我開始出現錯誤:com.google.android.gms.common.internal.safe parcel.safe parcelable not found

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:[email protected]') { 
     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' 

回答

139

在您的搖籃文件谷歌播放服務的所有版本和火力應該使用同一版本

當你使用:

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

你應該使用:

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

+0

這個工作給我,謝謝! –

+2

問題解決了! –

+0

謝謝@GuillaumeAgis –

9

這是一個Android Studio中的錯誤,它並不提供自動升級火力libs喜歡它的play-services * libs。

自動更新

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

沒有自動更新(需要手動了版本一樣播放服務*)

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

謝謝你的解決方案:) :) –

2

確保您的谷歌服務版本的火力版本相匹配。 當前正在編譯'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',以便版本匹配。

13

您必須在同一個版本的所有谷歌播放服務專線:

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' 
+0

任何想法爲什麼文檔的使用'''com.google.android.gms:play-services-base:11.0.4 '''?感謝您拯救我的理智! – Wainage

+0

最後更新是...你也可以使用它... –

2

使用這樣的事情:

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' 

確保選中應用插件有以下依賴性。