我正在尝试在应用程序中实现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类,它给了我一个错误,根本找不到它,它说它不能转换为Context对象。如果删除库,错误消失了。
Logcat:
D:\ project \ uumoo_android \ app \ src \ main \ java \ net \ uumoo \ pocket \ android \ Services \ MyFirebaseMessagingService.java:66: 错误:类型不兼容:MyFirebaseMessagingService不能为 转换为上下文
private Context context = MyFirebaseMessagingService.this;
这是我的应用程序。
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'
这是我的项目成果
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
}
答案 0 :(得分:1)
我只是降级了Firebase-core。它可以再次工作
// @see https://stackoverflow.com/a/53371918/3152877
// ##################### Firebase Core ###########################
implementation 'com.google.firebase:firebase-core:16.0.6'
// @see https://stackoverflow.com/a/53371918/3152877
//###################### 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'