Search code examples
xamarinxamarin.androidtwilioxamarin-bindingtwilio-programmable-voice

Problems using Twilio Programmable Voice in a Xamarin Android Bindings Library


I created a bindings library project to be able to run the Twilio's Android Programmable Voice SDK (v 2.0.5 - link to download .aar file).

I added this lines of code in Metadata.xml to fix some of the errors:

<!-- solving: Error CS0102  The type 'ErrorEventArgs' already contains a definition for 'P0'  TwilioBindings C:\...\TwilioBindings\obj\Debug\generated\src\Com.Twilio.Voice.IRegistrationListener.cs    -->
<attr path="/api/package[@name='com.twilio.voice']/interface[@name='RegistrationListener']/method[@name='onError']" name="managedName">RegistrationListenerOnError</attr>  
<attr path="/api/package[@name='com.twilio.voice']/interface[@name='UnregistrationListener']/method[@name='onError']" name="managedName">UnregistrationListenerOnError</attr>

<!-- Error  CS0234  The type or namespace name 'InternalCall' does not exist in the namespace 'Com.Twilio.Voice' (are you missing an assembly reference?)   TwilioBindings  C:\...\TwilioBindings\obj\Debug\generated\src\Com.Twilio.Voice.Call.cs -->
<attr path="/api/package[@name='com.twilio.voice']/class[@name='InternalCall']" name="visibility">public</attr>

<!-- Error  CS0115  'Call.OnWarning(IDictionary)': no suitable method found to override TwilioBindings  C:\...\TwilioBindings\obj\Debug\generated\src\Com.Twilio.Voice.Call.cs -->
<attr path="/api/package[@name='com.twilio.voice']/class[@name='Call']/method[@name='onWarning' and count(parameter)=1 and parameter[1][@type='java.util.HashMap']]/parameter[1]" name="type">java.util.HashMap&lt;java.lang.String, java.lang.Object&gt;</attr>

It compiles successfully but when i call Voice.Call() the method doesn't return anything and if i call it in the ui thread the ui keeps stuck forever. I paused the debugger so i can see what part of the code was running and it's waiting for the return of the follow line in Com.Twilio.Voice.Voice:

global::Com.Twilio.Voice.Call __ret = global::Java.Lang.Object.GetObject<global::Com.Twilio.Voice.Call> (JNIEnv.CallStaticObjectMethod  (class_ref, id_call_Landroid_content_Context_Ljava_lang_String_Ljava_util_Map_Lcom_twilio_voice_Call_Listener_, __args), JniHandleOwnership.TransferLocalRef);

My hint is that probably some of the lines that i added in Metadata.xml are incorrect or i need to add some more.

I've got some warnings that may help solving the problem:

Warning     Type com.getkeepsafe.relinker.ReLinker: FxDG naming violation: Type name 'ReLinker' matches namespace part 'Relinker'.  RelinkerBindings    C:\...\RelinkerBindings\BINDINGSGENERATOR   

Warning     Skipping Com.Getkeepsafe.Relinker.ReLinkerInstance.Force, due to a duplicate field, method or nested type name. RelinkerBindings    C:\...\RelinkerBindings\BINDINGSGENERATOR   

Warning     Type com.getkeepsafe.relinker.ReLinker: FxDG naming violation: Type name 'ReLinker' matches namespace part 'Relinker'.  RelinkerBindings    C:\...\RelinkerBindings\BINDINGSGENERATOR   

Warning     ignoring option UseSplitVerifier; support was removed in 8.0    RelinkerBindings    C:\...\RelinkerBindings\JARTOXML        

Warning CS0108  'Call.IInternalListener.OnConnectFailure(Call, CallException)' hides inherited member 'Call.IListener.OnConnectFailure(Call, CallException)'. Use the new keyword if hiding was intended.   TwilioBindings  C:\...\TwilioBindings\obj\Debug\generated\src\Com.Twilio.Voice.Call.cs  17  Active

Warning CS0108  'Call.IInternalListener.OnConnected(Call)' hides inherited member 'Call.IListener.OnConnected(Call)'. Use the new keyword if hiding was intended.   TwilioBindings  C:\...\TwilioBindings\obj\Debug\generated\src\Com.Twilio.Voice.Call.cs  21  Active

Warning CS0108  'Call.IInternalListener.OnDisconnected(Call, CallException)' hides inherited member 'Call.IListener.OnDisconnected(Call, CallException)'. Use the new keyword if hiding was intended.   TwilioBindings  C:\...\TwilioBindings\obj\Debug\generated\src\Com.Twilio.Voice.Call.cs  29  Active

Warning CS0108  'Event.GetType()' hides inherited member 'object.GetType()'. Use the new keyword if hiding was intended.    TwilioBindings  C:\...\TwilioBindings\obj\Debug\generated\src\Com.Twilio.Voice.Impl.Session.Event.cs    222 Active

Warning IDE0006 Error encountered while loading the project. Some project features, such as full solution analysis for the failed project and projects that depend on it, have been disabled.   TwilioBindings      1   Active

Warning     For type Com.Twilio.Voice.InternalCall, base interface com.twilio.voice.RTCMonitorCommand.Listener is invalid.  TwilioBindings  C:\...\TwilioBindings\BINDINGSGENERATOR     

Warning     For type Com.Twilio.Voice.InternalCall, base interface com.twilio.voice.EventPublisher.EventPublisherListener is invalid.   TwilioBindings  C:\...\TwilioBindings\BINDINGSGENERATOR     

Warning     Type com.twilio.voice.Voice: FxDG naming violation: Type name 'Voice' matches namespace part 'Voice'.   TwilioBindings  C:\...\TwilioBindings\BINDINGSGENERATOR     

Warning     Type com.twilio.voice.Voice: FxDG naming violation: Type name 'Voice' matches namespace part 'Voice'.   TwilioBindings  C:\...\TwilioBindings\BINDINGSGENERATOR     

Warning     Invalid parameter type com.twilio.voice.EventPayload.WarningName in method OnWarningCleared in managed type Com.Twilio.Voice.InternalCall.  TwilioBindings  C:\...\TwilioBindings\BINDINGSGENERATOR     

Warning     Invalid parameter type com.twilio.voice.EventPayload.WarningName in method OnWarningCleared in managed type Com.Twilio.Voice.Call.  TwilioBindings  C:\...\TwilioBindings\BINDINGSGENERATOR     

Warning     ignoring option UseSplitVerifier; support was removed in 8.0    TwilioBindings  C:\...\TwilioBindings\JARTOXML

Note: Because Twilio's Android Programmable Voice SDK has a dependency (ReLinker 1.2.2 (link to download .aar file)) i had to create another bindings library project (RelinkerBindings) to contain that dependency and then i referenced it in Twilio's bindings project.

I never did any bindings project before in xamarin so i'm kinda new to this.

Does anyone one knows how to solve this problem ?

Thanks in advance.

EDIT:

I've saw the logcat logs and this is what happens when i call Voice.Call():

04-27 10:17:00.118  7208  7247 E CallCommandHandlerImpl: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/getkeepsafe/relinker/ReLinker;
04-27 10:17:00.118  7208  7247 E CallCommandHandlerImpl:        at com.twilio.voice.UserAgent.loadLibrary(UserAgent.java:261)
04-27 10:17:00.118  7208  7247 E CallCommandHandlerImpl:        at com.twilio.voice.UserAgent.<init>(UserAgent.java:57)
04-27 10:17:00.118  7208  7247 E CallCommandHandlerImpl:        at com.twilio.voice.UserAgent.get(UserAgent.java:107)
04-27 10:17:00.118  7208  7247 E CallCommandHandlerImpl:        at com.twilio.voice.CallCommandHandlerImpl.run(CallCommandHandlerImpl.java:50)
04-27 10:17:00.118  7208  7247 E CallCommandHandlerImpl: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.getkeepsafe.relinker.ReLinker" on path: DexPathList[[zip file "/data/app/com.globalactone.ecare-1/base.apk"],nativeLibraryDirectories=[/data/app/com.globalactone.ecare-1/lib/x86, /system/fake-libs, /data/app/com.globalactone.ecare-1/base.apk!/lib/x86, /system/lib, /vendor/lib]]
04-27 10:17:00.118  7208  7247 E CallCommandHandlerImpl:        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
04-27 10:17:00.118  7208  7247 E CallCommandHandlerImpl:        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
04-27 10:17:00.118  7208  7247 E CallCommandHandlerImpl:        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
04-27 10:17:00.118  7208  7247 E CallCommandHandlerImpl:        ... 4 more

Solution

  • I added a reference to the RelinkerBindings project wich contains a dependency of the Twilio's project but somehow the logs where showing that the RelinkerBindings wasn't being found, so i removed the reference to the project and added a reference to the Relinker dll file and it works now. Don't know why it wasn't working when it had a reference to the project.