I’ve been working on integrating a vendor’s SDK “ThirdParty” into my Xamarin Forms app “MyApp”. I ran into something with jar/aar binding that I figured out a hack for, but it seems like there should be a better way.
Intended Xamarin code structure - 6 assemblies as follows:
Code Project - Description
(1) MyApp - Cross Platform core code
References: (4)
(2) MyApp.IOS - IOS App
References: (4) (6)
(3) MyApp.Android - Android App
References: (4) (5)
Here, I hope not to have to include in this high-level project: - libThirdPartyClient.so as AndroidNativeLibrary and - ThirdPartyclient.jar as AndroidJavaLibrary
(4) ThirdPartyConnector - Cross-Platform ThirdParty sub-project
References: Nothing from 1-6
Where I will house common code and abstractions of things located down in projects (5) and (6), which are to be used by project (1).
(5) ThirdPartyConnector.Android - Binding Assembly
References: (4)
Contains implementations of abstractions from (4).
Here, I Expect to include in this project: - libThirdPartyClient.so as AndroidNativeLibrary and - ThirdPartyclient.jar as AndroidJavaLibrary
(6) ThirdPartyConnector.IOS - Binding Assembly
References: (4)
Contains implementations of abstractions from (4).
What I run into at runtime is that unless I include the libThirdPartyClient.so and ThirdPartyclient.jar files inside assembly (3) MyApp.Android (I had originally included them in (5) ThirdPartyConnector.Android), the so and jar files do not get included into the final APK file. At runtime, then the app runs into JNI Java Class Not Found errors because the so and jar file content isn’t present/included in the built APK file.
What I really don’t like about it is that no code in assembly (3) has any direct calls into these subordinate java artifacts that are needed at a much lower level (5) in the solution at runtime. My project (3) is big enough on its own – hence my motivation to break things down into logical sub-projects.
Questions:
1.Does anyone have any suggestions on how these assemblies can better linked/embeded native items whem you have separate projects like (3) and (5)?
2.If one had, for example 4 more jars from other vendors/packages, would one have to also include all of these jar and aar files in my assembly (3) project? Seems messy, but doable if one really has to.
3.This post has been focused on Android, but do you have to do similar things for IOS, when it comes to embedding native code? Will I have to embed code used by project (6) into project (2)?
Any tips, pointers, or insight into how this works at compile-time will be greatly appreciated.