不兼容的类型:FirebaseMessagingService 无法转换为 Context

Incompatible types: FirebaseMessagingService cannot be converted to Context

我正在尝试在我的应用程序中实施 ML Kit:自然语言 API 和 ML Kit:语言识别模型,我已经实施了所有设置并且工作正常,但是当我尝试实施这些设置时。

com.google.firebase:firebase-ml-natural-language:22.0.0
com.google.firebase:firebase-ml-natural-language-language-id-model:20.0.7

FirebaseMessagingService class 它给我一个错误,它根本找不到它,它说它不能转换成上下文对象。如果删除库,错误就消失了。

Logcat:

D:\project\uumoo_android\app\src\main\java\net\uumoo\pocket\android\Services\MyFirebaseMessagingService.java:66: error: incompatible types: MyFirebaseMessagingService cannot be converted to Context

private Context context = MyFirebaseMessagingService.this;

这是我的应用程序 gradle。

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:support-vector-drawable:27.1.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.firebase:firebase-messaging:17.3.0'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:design:27.1.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.wdullaer:materialdatetimepicker:3.6.2'
implementation 'com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.3'
implementation 'com.github.ittianyu:BottomNavigationViewEx:1.2.4'
//implementation 'com.squareup.retrofit2:retrofit:2.2.0'
//implementation 'com.google.code.gson:gson:2.8.2'
//implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
implementation 'com.android.volley:volley:1.1.1'


implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.tozny:java-aes-crypto:1.1.0'
implementation 'com.scottyab:aescrypt:0.0.1'
implementation 'com.kbeanie:multipicker:1.5@aar'
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
implementation 'com.androidadvance:topsnackbar:1.1.1'
implementation 'com.github.delight-im:Android-AdvancedWebView:v3.0.0'
implementation 'com.github.XuDaojie:QRCode-Android:v0.4.2'
implementation 'com.google.firebase:firebase-ml-vision:18.0.1'
implementation 'com.github.zomato:androidphotofilters:1.0.1'
implementation 'com.yakivmospan:scytale:1.0.1'
implementation 'com.xw.repo:bubbleseekbar:3.19'
implementation 'com.google.maps.android:android-maps-utils:0.5+'

// barcode reader library only use for UI
implementation 'info.androidhive:barcode-reader:1.1.5'

implementation "com.google.code.gson:gson:$rootProject.gsonVersion"

implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-auth-api-phone:16.0.0'

//implementation 'com.google.firebase:firebase-core:17.2.1'
//dentify the language of text with ML Kit
implementation 'com.google.firebase:firebase-ml-natural-language:22.0.0'
  implementation 'com.google.firebase:firebase-ml-natural-language-language-id-model:20.0.7'
}
apply plugin: 'com.google.gms.google-services'

这是我的项目gradle

dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    classpath 'com.google.gms:google-services:3.2.0'
    // new
   // classpath 'com.google.gms:google-services:4.3.2'  // Google Services plugin
}

我刚刚降级了 firebase-core 。它又可以工作了

 // @see 
// ##################### Firebase Core ###########################
implementation 'com.google.firebase:firebase-core:16.0.6'

// @see 
//###################### FCM ####################################
implementation 'com.google.firebase:firebase-messaging:17.3.2'

// ################### MAP ######################################
implementation 'com.google.android.gms:play-services-maps:15.0.1'

//#################### identify the language of text with ML Kit################
implementation 'com.google.firebase:firebase-ml-natural-language:18.2.0'
implementation 'com.google.firebase:firebase-ml-natural-language-language-id-model:18.0.2'