Forum Xamarin.Android

Android obfuscation build error: "LinkAssemblies task failed unexpectedly"

Hello,

I'm getting an Android linker error I can't figure out. Any hints that would help with a workaround would be welcome, including more info about what Xamarin does behind the scenes, as it's sort of a black box.


My setup

  • Xamarin Studio 5.9.4.5
  • Xamarin.Android 5.1.4 (Indie Edition).
  • Release mode build.
  • Android Minimum Version: 5.0 (API 21)
  • Android Target Version: 5.0 (API 21)
  • Xamarin Target Framework: Android 5.0 (Lollipop)
  • Obfuscation of names via ConfuserEx 0.5.
  • Android Build/Linker behavior: "Link SDKs Only"

Build actions and results

  • If I do a "Clean All" and then a "Build All", then it finishes without error.
  • If I do a clean followed by an "Archive For Publishing", then I get the "LinkAssemblies task failed unexpectedly" error with details as follows:

    Error MSB4018: The "LinkAssemblies" task failed unexpectedly.
    System.ArgumentException: An item with the same key has already been added.
    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
    at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer`1 comparer)
    at MonoDroid.Tuner.MarkJavaObjects.GetTypesInModule(ModuleDefinition module)
    at MonoDroid.Tuner.MarkJavaObjects.FindType(TypeDefinition type, String fullname)
    at MonoDroid.Tuner.MarkJavaObjects.GetHelperType(TypeDefinition type, String suffix)
    at MonoDroid.Tuner.MarkJavaObjects.PreserveAdapter(TypeDefinition type)
    [...]


Obfuscation steps

Inside my Android app's csproj file I have the following:

<Target Name="Obfuscate" AfterTargets="_CopyIntermediateAssemblies" Condition="'$(Configuration)' == 'Release'">
    <Exec Command="RunAndroidObfuscate.bat" WorkingDirectory="." />
</Target>

My batch file replaces the main app DLL with an obfuscated version in the following folder. It is set up to only modify that single DLL:

  obj\Release\assemblies\MyMainApp.dll

The obfuscation is running without errors and successfully replaces the DLL.

Answers

Sign In or Register to comment.