xamarin android build error: "Failed to create JavaTypeInfo for class"
Based on your builder error, the ExportAttribute
is used to instruct the “Java code generator to export a Java method that becomes an Android Callable Wrapper (ACW)” and Dictionary<string, object>
is not a Java object (duh) and the Java code generator has no idea how to handle it.
[Java.Interop.Export("navigateTo")]
[JavascriptInterface]
public void NavigateTo(Dictionary<string, object> dict)
{
Console.WriteLine(dict);
}
So the simple fix to this problem was to switch the parameter type from Dictionary<string, object>
to Java.Lang.Object
. Now the Java code generator can properly generate an ACW and the compilation succeeds.
[Java.Interop.Export("navigateTo")]
[JavascriptInterface]
public void NavigateTo(Java.Lang.String dict)
{
Console.WriteLine(dict);
}
Failed to create JavaTypeInfo for class - build error in Visual Studio 2019, Xamarin Forms template
I got a similar error: (the details are different though, see below)
Failed to create JavaTypeInfo for class:
Android.Support.V4.View.Accessibility.AccessibilityManagerCompat/IAccessibilityStateChangeListenerImplementor
due to System.IO.DirectoryNotFoundException:
Could not find a part of the path '...\obj\Debug\81\android\src\mono\android\support\v4\view\accessibility\AccessibilityManagerCompat_AccessibilityStateChangeListenerImplementor.java'.
This is on Visual Studio 2019, after upgrading to Xamarin Forms 4.x, though I think the upgrade doesn't matter here.
This issue has been reported here on the visual studio developer community - https://developercommunity.visualstudio.com/content/problem/521034/failed-to-create-javatypeinfo.html
For me, it turned out to be a 'Long Path' issue, as reported by a few other users in the dev community (refer to the above link). Once I moved my solution a couple of directories up, to reduce the overall path length, it started working fine.
So this is definitely related to the MAX_PATH problem on Windows. This is a long dicussion about this here . Hopefully according to microssoft support team they are planing solve this issue and removing MAX_PATH as limit; but at the moment I use last edition of visual studio (Microsoft Visual Studio 2019 Version 16.2.3) I still get the same error.
Accoridng Microsfot Support team :
Some background on why those .java names are so long. Java requires that the class name must match the filename (Unlikc C#). And because some of these android types have really long names we are in a position where we cannot change them ð For now moving the project closer to the root of the drive is the easiest solution.
I solve the problem by moving my project to up directories and renaming long folder names.