I'm building a Xamarin android app.
After xamarin update I get a build error. I can't tell if that is related at all but what worked before now throws an exception: ClassNotFoundException
. The class exists and is a proper activity. There was no change in that area at all.
I've seen many SO threads in that regard but they all suggest to clean solution, delete build folder etc. And that doesn't help me unfortunately.
What I realise is that in the exception message
W/monodroid( 4201): JNIEnv.FindClass(Type) caught unexpected exception: Java.Lang.ClassNotFoundException: md56629fa8edd4a41a77563f74c5f9a5f792.MainActivity
the md5 part is not the same as the folder where the MainActivity.class resides in (md56b5cfc81a7b5c4227a0c9a4dcb7dab856
). When I delete that folder a new one is generated during a build. Its md5 is different again. But the exception reappears, asking for the same old md5 as before.
My questions:
1.) What can I do to make JNIEnv look for the right md5?
2.) How are those md5 generated and why
Thanks.
Xamarin generates an MD5 sum for all types that have a Android Callable Wrapper (ACW), unless you explicitly give it a name. I guess this is done to avoid collisions with other types, which could live in the same package name. These are generated at build time.
In order to set your own name on a type inheriting from Java.Lang.Object
, these are types like Activity
, Adapter
, View
and many more. You simply add a Register
attribute to your class:
[Register("my.cool.package.MyTypeName")]
public class MyTypeName : SomeJavaType
{
}
For classes such as Activity
you can alternatively use the Name
property in the Activity
attribute:
[Activity(Label = "MyActivity", Name = "my.cool.package.MyActivity")]
public class MyActivity : Activity
{
}