Hi, I was wondering if there is a sample showing how to embed Xamarin in an Android C++ project? I'm using Android Studio with a CMake project. I've patterned my project similar to the code found here:
www.mono-project.com/docs/advanced/embedding/
It looks like I'm linking correctly, but I'm not sure what assemblies need to be included, or where they are expected. My sample app just dies in the emulator a the mono_init() step. The mono_get_runtime_build_info() returns "5.10.1 (tarball)".
I've pulled the Xamarin source, and I'm using the .so files found after bulding. My java static initializer looks like this:
public class MainActivity extends AppCompatActivity { // Used to load the 'native-lib' library on application startup. static { System.loadLibrary("native-lib"); // the hello world app // Xamarin libraries System.loadLibrary("mono-android.debug"); System.loadLibrary("mono-btls-shared"); System.loadLibrary("MonoPosixHelper"); System.loadLibrary("mono-profiler-aot"); System.loadLibrary("mono-profiler-log"); System.loadLibrary("monosgen-2.0"); }
My C++ call looks like this:
extern "C" JNIEXPORT void JNICALL Java_com_hellondk_MainActivity_startMono(JNIEnv *env, jobject /* this */) { char *pStr = mono_get_runtime_build_info(); // this works MonoDomain *domain = mono_jit_init_version("RootDomain", "v4.0.30319"); // we die here
Answers
I've gotten a little farther with my project, but I'm still stuck. It appears when you build a C# app using Xamarin in Visual Studio, the .apk file contains 'classes.dex' with the required mono runtime. However, my app is C++, and I would like to host the mono runtime. Perhaps someone here knows the steps to building a mono/Xamarin filled classes.dex the same way visual studio is doing it?
The next step is how does mono_init know to find it there?
Did you eventually find the solution? I'm trying to do the same thing now.