6. Why should we use binding?
Many existing java libraries for Android
Use them in your app with little effort
7. How does binding work?
Picture from xamarin.com
https://developer.xamarin.com/guides/android/advanced_topics/java_integration_overview/binding-a-java-library/
9. Why MCWs?
Encapsulate JNI use so that client code doesn't need to know about the
underlying complexity
Permit sub-classing Java types and implementing Java interfaces
10. Under the hood
JNI
The Java Native Interface (JNI) is a programming framework that enables Java
code running in a Java Virtual Machine (JVM) to call and be called by native
applications (programs specific to a hardware and operating system platform) and
libraries written in other languages such as C, C++ and assembly.
(Wikipedia)
11. Example: Constructor Binding
int value = 42;
IntPtr class_ref = JNIEnv.FindClass ("java/lang/Integer");
IntPtr id_ctor_I = JNIEnv.GetMethodID (class_ref, "<init>", "(I)V");
IntPtr lrefInstance = JNIEnv.NewObject (class_ref, id_ctor_I, new JValue (value));
// Dispose of lrefInstance, class_ref…
12. Creating MCWs for your Xamarin project
Have a java library (jar)
Create a Xamarin Binding project
Insert jar into project
Build the project
Creates dll consisting of the MCW
13. Jar Build Actions
Input Jar
Will create the actual bindings for this jar
EmbeddedReferenceJar
17. Transforms
EnumFields.xml
Converts Constants to Enums
EnumMethods.xml
Changes parameters in methods to use Enums
Metadata.xml
Various add/remove/edit transforms