Forum Xamarin.Android

Firebase Smart Reply not working on Xamarin.Android

Hi! I'm trying to use Firebase Smart Reply in my Xamarin.Android project. I followed the Firebase guide and set it up in my Xamarin project. However, it is not working. I'm using Visual Studio 2019 16.6.0.

I added the following Nuget packages for Firebase Smart Reply:
<PackageReference Include="Xamarin.Firebase.ML.Natural.Language"> <Version>122.0.0-preview02</Version> </PackageReference> <PackageReference Include="Xamarin.Firebase.ML.Natural.Language.Id.Model"> <Version>120.0.7-preview02</Version> </PackageReference> <PackageReference Include="Xamarin.Firebase.ML.Natural.Language.Model"> <Version>120.0.7-preview02</Version> </PackageReference> <PackageReference Include="Xamarin.Firebase.ML.Natural.Language.Smart.Reply"> <Version>118.0.7-preview02</Version> </PackageReference> <PackageReference Include="Xamarin.Firebase.ML.Natural.Language.Smart.Reply.Model"> <Version>120.0.7-preview02</Version> </PackageReference> <PackageReference Include="Xamarin.Firebase.ML.Natural.Language.Translate"> <Version>122.0.0-preview02</Version> </PackageReference>

Also added the following in my Android Options to disable compression of Smart Reply model file:
<AndroidStoreUncompressedFileExtensions>.tflite;tflite</AndroidStoreUncompressedFileExtensions>

However, on running, Smart Reply throws this exception every time the code calls SuggestReplies() function:
com.google.firebase.ml.common.FirebaseMLException: Failed to generate smart reply

The console log shows these lines when the exception is thrown:
I/mono-stdout( 6829): Log: SmartReply Test 5 - Conversation
W/monodroid-assembly( 6829): typemap: unable to find mapping to a managed type from Java type 'com/google/android/gms/tasks/zzu'
I/mono-stdout( 6829): Log: 2nd call
I/mono-stdout( 6829): Log: Start Time: 5/23/2020 7:11:27 PM
W/monodroid-assembly( 6829): typemap: unable to find mapping to a managed type from Java type 'com/google/android/gms/tasks/zzu'
W/monodroid-assembly( 6829): typemap: unable to find mapping to a Java type from managed type 'System.Int32, mscorlib'
W/monodroid-assembly( 6829): typemap: unable to find mapping to a Java type from managed type 'System.Int32, mscorlib'
D/Mono ( 6829): DllImport searching in: '__Internal' ('(null)').
D/Mono ( 6829): Searching for 'java_interop_jnienv_is_assignable_from'.
D/Mono ( 6829): Probing 'java_interop_jnienv_is_assignable_from'.
D/Mono ( 6829): Found as 'java_interop_jnienv_is_assignable_from'.

I/tflite ( 6829): Initialized TensorFlow Lite runtime.Initialized TensorFlow Lite runtime.

W/monodroid-assembly( 6829): typemap: unable to find mapping to a Java type from managed type 'System.Int32, mscorlib'
E/ModelResourceManager( 6829): Error preloading model resource
E/ModelResourceManager( 6829): com.google.firebase.ml.common.FirebaseMLException: Couldn't open language detection model file

E/ModelResourceManager( 6829): at com.google.firebase.ml.naturallanguage.languageid.internal.LanguageIdentificationJni.zzl(com.google.firebase:[email protected]@22.0.0:23)
E/ModelResourceManager( 6829): at com.google.firebase.ml.naturallanguage.languageid.FirebaseLanguageIdentification$zzb.zzl(com.google.firebase:[email protected]@22.0.0:6)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzde.zzf(com.google.firebase:[email protected]@22.0.0:53)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzde$zza.zzdn(com.google.firebase:[email protected]@22.0.0:7)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzde$zza.call(com.google.firebase:[email protected]@22.0.0:24)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzco.zza(com.google.firebase:[email protected]@22.0.0:31)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzcr.run(Unknown Source:4)
E/ModelResourceManager( 6829): at android.os.Handler.handleCallback(Handler.java:873)
E/ModelResourceManager( 6829): at android.os.Handler.dispatchMessage(Handler.java:99)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzb.dispatchMessage(com.google.firebase:[email protected]@18.0.7:6)
E/ModelResourceManager( 6829): at android.os.Looper.loop(Looper.java:193)
E/ModelResourceManager( 6829): at android.os.HandlerThread.run(HandlerThread.java:65)
E/ModelResourceManager( 6829): Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
E/ModelResourceManager( 6829): at android.content.res.AssetManager.nativeOpenAssetFd(Native Method)
E/ModelResourceManager( 6829): at android.content.res.AssetManager.openFd(AssetManager.java:768)
E/ModelResourceManager( 6829): at com.google.firebase.ml.naturallanguage.languageid.internal.LanguageIdentificationJni.zzl(com.google.firebase:[email protected]@22.0.0:11)
E/ModelResourceManager( 6829): ... 11 more
W/monodroid-assembly( 6829): typemap: unable to find mapping to a Java type from managed type 'Android.Text.IInputFilter, Mono.Android'
W/FirebaseSmartReply( 6829): Failed to identify the language for the conversation
I/chatty ( 6829): uid=10090(com.kapildhaimade.) FirebaseMLHandl identical 3 lines
W/FirebaseSmartReply( 6829): Failed to identify the language for the conversation
V/PredictOnDevice( 6829): input blacklist: "(?i).amber alert.,(?i).http.|.www." context blacklist: "" suggestion blacklist: "(?i)lmao,(?i)you welcome!,(?i)Love you to :),😘,😙,😚,💍,(?i)i'm good and you,(?i).(\b)man\pP($|\s.),(?i).(\b)woman\pP($|\s.),(?i).(\b)men\pP($|\s.),(?i).(\b)women\pP($|\s.),(?i).(\b)boy\pP($|\s.),(?i).(\b)girl\pP($|\s.),(?i).(\b)babe\pP($|\s.),(?i).(\b)baby\pP($|\s.),(?i).(\b)sir\pP($|\s.*)"

I haven't been able to get it running after much troubleshooting. I did try to access the Smart Reply model file 'hobbes.tflite' using Assets.Open() and it seems to work so I'm not sure which file it is unable to find.
Any ideas what I can do to make this work? Thank you for the help :smile:

Sign In or Register to comment.