我正在尝试在我的应用中实施Firebase MlKit转换。 我已经将firebase语言依赖项添加到我的gradle文件中
implementation 'com.google.firebase:firebase-ml-natural-language:19.0.0'
implementation 'com.google.firebase:firebase-ml-natural-language-language-id-model:19.0.0'
之后,我遵循了Firebase文档中的示例:Translate text with Ml Kit on Android
当我运行我的应用程序时,出现以下错误
E/ModelResourceManager: Error preloading model resource
com.google.firebase.ml.common.FirebaseMLException: Couldn't load translate native code library. Please check your app setup to include the firebase-ml-natural-language-translate-model dependency
at com.google.firebase.ml.naturallanguage.translate.internal.TranslateJni.zzck(Unknown Source:12)
at com.google.firebase.ml.naturallanguage.translate.FirebaseTranslator$zza.zzck(Unknown Source:8)
at com.google.android.gms.internal.firebase_ml_naturallanguage_translate.zzdj.zzf(Unknown Source:56)
at com.google.android.gms.internal.firebase_ml_naturallanguage_translate.zzdl.zzcs(Unknown Source:7)
at com.google.android.gms.internal.firebase_ml_naturallanguage_translate.zzdl.call(Unknown Source:24)
at com.google.android.gms.internal.firebase_ml_naturallanguage_translate.zzdd.zza(Unknown Source:29)
at com.google.android.gms.internal.firebase_ml_naturallanguage_translate.zzdc.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.google.android.gms.internal.firebase_ml_naturallanguage_translate.zzb.dispatchMessage(Unknown Source:6)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:65)
这是我的代码:
FirebaseTranslatorOptions firebaseTranslatorOptions = new FirebaseTranslatorOptions.Builder()
.setSourceLanguage(FirebaseTranslateLanguage.EN)
.setTargetLanguage(FirebaseTranslateLanguage.ES)
.build();
final FirebaseTranslator firebaseTranslator = FirebaseNaturalLanguage.getInstance().getTranslator(firebaseTranslatorOptions);
FirebaseModelDownloadConditions firebaseModelDownloadConditions = new FirebaseModelDownloadConditions.Builder().build();
firebaseTranslator.downloadModelIfNeeded(firebaseModelDownloadConditions)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
textView.setText("Model downloaded");
firebaseTranslator.translate("Hello")
.addOnSuccessListener(new OnSuccessListener<String>() {
@Override
public void onSuccess(String s) {
textView2.setText(s);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
textView2.setText(e.getMessage());
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
textView.setText("Download failed");
}
});
有人对解决这个问题有什么建议吗?
答案 0 :(得分:0)
从错误消息看来,您还需要包括:
implementation 'com.google.firebase:firebase-ml-natural-language-translate-model:19.0.0'