java.lang.IncompatibleClassChangeError使用Firebase和Google Play服务导致应用崩溃

时间:2016-11-10 11:59:10

标签: android firebase android-gradle firebase-analytics

当我使用firebase和google play服务运行我的应用时,我收到了以下崩溃日志

模拟器中的异常:

11-10 17:14:39.716 2645-2645/com.winjit.musiclib.sample E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.winjit.musiclib.sample, PID: 2645
  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.firebase.iid.zzg' appears in /data/app/com.winjit.musiclib.sample-1/base.apk)
      at com.google.firebase.iid.zzg.zzeC(Unknown Source)
      at com.google.firebase.iid.zzg.<init>(Unknown Source)
      at com.google.firebase.iid.zzg.<init>(Unknown Source)
      at com.google.firebase.iid.zzd.zzb(Unknown Source)
      at com.google.firebase.iid.FirebaseInstanceIdService.zziB(Unknown Source)
      at com.google.firebase.iid.FirebaseInstanceIdService.zzA(Unknown Source)
      at com.google.firebase.iid.zzb.onStartCommand(Unknown Source)
      at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3010)
      at android.app.ActivityThread.-wrap17(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1442)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:148)
      at android.app.ActivityThread.main(ActivityThread.java:5417)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

设备中的例外:

11-10 17:30:50.724 9161-9161/com.winjit.musiclib.sample E/FirebaseApp: Firebase API initialization failure.
   java.lang.reflect.InvocationTargetException
       at java.lang.reflect.Method.invoke(Native Method)
       at com.google.firebase.FirebaseApp.zza(Unknown Source)
       at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
       at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
       at com.google.firebase.FirebaseApp.zzbu(Unknown Source)
       at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
       at android.content.ContentProvider.attachInfo(ContentProvider.java:1801)
       at android.content.ContentProvider.attachInfo(ContentProvider.java:1776)
       at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
       at android.app.ActivityThread.installProvider(ActivityThread.java:5464)
       at android.app.ActivityThread.installContentProviders(ActivityThread.java:5037)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4977)
       at android.app.ActivityThread.-wrap1(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1562)
       at android.os.Handler.dispatchMessage(Handler.java:111)
       at android.os.Looper.loop(Looper.java:207)
       at android.app.ActivityThread.main(ActivityThread.java:5769)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:681)
    Caused by: 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.firebase.iid.zzg' appears in /data/app/com.winjit.musiclib.sample-1/base.apk)
       at com.google.firebase.iid.zzg.zzeC(Unknown Source)
       at com.google.firebase.iid.zzg.<init>(Unknown Source)
       at com.google.firebase.iid.zzg.<init>(Unknown Source)
       at com.google.firebase.iid.zzd.zzb(Unknown Source)
       at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
       at java.lang.reflect.Method.invoke(Native Method) 
       at com.google.firebase.FirebaseApp.zza(Unknown Source) 
       at com.google.firebase.FirebaseApp.initializeApp(Unknown Source) 
       at com.google.firebase.FirebaseApp.initializeApp(Unknown Source) 
       at com.google.firebase.FirebaseApp.zzbu(Unknown Source) 
       at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source) 
       at android.content.ContentProvider.attachInfo(ContentProvider.java:1801) 
       at android.content.ContentProvider.attachInfo(ContentProvider.java:1776) 
       at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source) 
       at android.app.ActivityThread.installProvider(ActivityThread.java:5464) 
       at android.app.ActivityThread.installContentProviders(ActivityThread.java:5037) 
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4977) 
       at android.app.ActivityThread.-wrap1(ActivityThread.java) 
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1562) 
       at android.os.Handler.dispatchMessage(Handler.java:111) 
       at android.os.Looper.loop(Looper.java:207) 
       at android.app.ActivityThread.main(ActivityThread.java:5769) 
       at java.lang.reflect.Method.invoke(Native Method) 
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:681) 
11-10 17:30:50.866 9161-9195/com.winjit.musiclib.sample E/FA: Task exception on worker thread: 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.firebase.iid.zzg' appears in /data/app/com.winjit.musiclib.sample-1/base.apk): com.google.android.gms.measurement.internal.zzt.zzEd(Unknown Source)

以下是我的gradle依赖项:

compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.google.android.gms:play-services-ads:9.0.0'
compile 'com.google.firebase:firebase-core:9.0.0'

// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

尝试编译

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

而不是

      compile 'com.google.firebase:firebase-core:9.0.0'

还可以通过SDK Manager更新到最新的google-play-services和google存储库:

enter image description here

尝试使用此解决方案。我用上面的解决方案解决了问题。我希望它对你有用。