gpt4 book ai didi

java - Firebase MLKIT 翻译 (firebase-ml-natural-language-translate-model) 的依赖性错误

转载 作者:行者123 更新时间:2023-12-02 05:29:55 29 4
gpt4 key购买 nike

我正在尝试在我的应用中实现 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");
}
});

有人有解决这个问题的建议吗?

最佳答案

从错误消息来看,您似乎还需要包括:

implementation 'com.google.firebase:firebase-ml-natural-language-translate-model:19.0.0'

关于java - Firebase MLKIT 翻译 (firebase-ml-natural-language-translate-model) 的依赖性错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56207296/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com