Search code examples
androidvisual-studioxamarindotfuscator

'Archive' action in Visual Studio Xamarin is packaging DLL before obfuscation


We've recently migrated from VS2017 to VS2019, building Xamarin Forms applications. We've had no problems with obfuscation for years and years, but now we've got a showstopper. To summarise: the project DLL inside the final APK file is the un-obfuscated version, not the obfuscated version.

If we build the Android app normally (in a Release configuration) it works fine: decompiling the file shows the obfuscated code as expected - completely unintelligible. It also successfully copies this from its working 'dfout' folder (under 'obj') to the 'bin' folder, so the build process propogates the obfuscated file as it should; everything is cool.

But...when you run 'Archive' to create an APK file...things work differently. After many hours of close examination we worked out exactly is happening, but we don't know why, and how to fix it: the project DLL (that should go inside the APK) is getting taken from the un-obfuscated code. The obfuscation then runs after the packaging has completed, leaving the correct DLLs in the 'obj' and 'bin' folders, but the one inside the packaged APK is the un-obfuscated version.

What on earth is going on here?


Solution

  • Found the solution to this in the comment thread of another StackOverflow question.

    Basically it's an issue with Dotfuscator working with VS2019, which requires some new Dotfuscator targeting files to work. Initially these too didn't work, but after deleting all bin and obj folders and restarting VS in Admin mode did the trick.

    Dotfuscator obfuscates stand alone assembly but not the APK archive