Vague Dotfuscator error on Xamarin.Android app

137 Views Asked by At

When running Dotfuscator on the release version of my Xamarin.Android app, I'm getting the following errors: enter image description here

If I disable Dotfuscator, then everything works fine. The weird part is that it works fine on a previous version of the app. In this new version of the app, I only added a handful of Android ContentProviders and one NuGet package. Nothing else. Any ideas?


Update

So as Joe Sewel explains, the issue is not technically with Dotfuscator, but with Xamarin.Android. The system from Xamarin, while generating Java classes, is populating their names from strings pulled from the .NET Intermediary Language files without first checking if those strings can actually be used as Java class names.

In my case, the issue was caused because I had two too many obfuscated C# classes in my project. Dotfuscator was renaming one of my class to do (after going through its normal renaming cycle: ab, ac, ad, and so on). Obviously, do cannot be used as a Java class name because it's a Java reserved keyword, so it caused a syntax error in the Xamarin tools later on. Removing or having Dotfuscator ignore any two classes in my project, caused Dotfuscator not to reach the do name in its cycle, and the issue was fixed. So until this bug is fixed in Xamarin.Android, there is such a thing as obfuscating too many classes in your project.

1

There are 1 best solutions below

2
On

What appears to be happening is that Dotfuscator is renaming a type to do - which is safe to do for non-library .NET Framework projects, because the .NET intermediate language doesn't reserve this word. Xamarin.Android's "glue" code is then creating Java code based on the obfuscated .NET assembly's type names, and since do is a reserved word in Java, this causes Java compiler errors.

To work around the issue, you could use the Dotfuscator Community user interface to exclude the type that is being renamed. You can use the renaming map file (e.g., DotfuscatorReports\Release\Renaming.xml) to see the mapping between the original source code names and the obfuscated names, including with the built-in decoding tool.

I work on the Dotfuscator team, and am answering in that capacity. I've also filed an issue with Xamarin, linking to this question, regarding these errors.