Firebase Cloud Messaging导致java.lang.NoSuchFieldError:没有类型I的GOOGLE_PLAY_SERVICES_VERSION_CODE字段

时间:2017-08-25 08:12:01

标签: android google-play-services firebase-cloud-messaging

我在项目中启用了FCM,但收到以下错误:

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.app, PID: 28654
 java.lang.NoSuchFieldError: No field GOOGLE_PLAY_SERVICES_VERSION_CODE of type I in class Lcom/google/android/gms/common/zzc; or its superclasses (declaration of 'com.google.android.gms.common.zzc' appears in /data/app/com.example.app-2/base.apk:classes40.dex)
     at com.google.android.gms.common.GoogleApiAvailability.<clinit>(Unknown Source)
     at com.google.android.gms.common.GoogleApiAvailability.getInstance(Unknown Source)
     at com.google.android.gms.common.api.GoogleApiClient$Builder.<init>(Unknown Source)
     at com.example.app.location.MyLocationManager.<init>(MyLocationManager.java:39)

在我的gradle文件中,我有:

provided "com.google.firebase:firebase-core:10.2.6"

并在其中一个库中:

compile libraries.firebase.messaging

在我的dependencies.gradle中:

libraries = [ 
  firebase : [
     crash    : "com.google.firebase:firebase-crash:$versions.google.play.services",
     messaging: "com.google.firebase:firebase-messaging:$versions.google.play.services"
  ],
]

在该行的MyLocationManager.java,我有:

GoogleApiClient apiClient = new GoogleApiClient.Builder(context)
        .addApi(LocationServices.API)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .build();

那么这个问题是什么?

1 个答案:

答案 0 :(得分:0)

替换compile libraries.firebase.messaging
compile 'com.google.firebase:firebase-messaging:11.2.0'选择,并确保为每个Google服务使用相同版本,即11.2.0