1 year ago

#376285

test-img

Jay Sidri

Xamarin.Android app crashes after running Obfuscar (Visual Studio for Mac)

I've got a basic Xamarin.Android project setup with Obfuscar configured

The obfuscar.xml:

<Obfuscator>
    <Var name="RenameProperties" value="true" />
    <Var name="RenameEvents" value="true" />
    <Var name="RenameFields" value="true" />
    <Var name="KeepPublicApi" value="false" />
    <Var name="HidePrivateApi" value="true" />
    <Var name="HideStrings" value="true" />
    <Var name="UseUnicodeNames" value="true" />
    <Var name="OptimizeMethods" value="true" />
    <Var name="InPath" value="/Users/user1/Documents/dev/project/src/MyProject.Android/bin/Debug" />
    <Var name="OutPath" value="$(InPath)/Obfuscator_Output" />
    <Module file="$(InPath)/MyProject.dll" />
</Obfuscator> 

And in the csproj file (I targeted Debug configuration to debug this issue):

<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Debug' ">
      <Message Importance="High" Text="Obfuscar task has been called." />
  <Exec WorkingDirectory="$(MonoAndroidIntermediateAssetsDir)" Command="$(Obfuscar) $(ProjectDir)obfuscar.xml" />
  <Copy SourceFiles="$(TargetDir)MyProject.dll" DestinationFolder="$(MonoAndroidIntermediateAssetsDir)" />
  </Target>

Obfuscation does seem to work.. mapping.txt is generated and I see the following in the build logs:

Target AfterBuild:
    Obfuscar task has been called.
    mono /Users/user1/.nuget/packages/obfuscar/2.2.33/build/../tools/Obfuscar.Console.exe /Users/user1/Documents/dev/project/src/MyProject.Android/obfuscar.xml
    Note that Rollbar API is enabled by default to collect crashes. If you want to opt out, please run with -s switch
    Loading project /Users/user1/Documents/dev/project/src/MyProject.Android/obfuscar.xml...Processing assembly: Solo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
    Loading assemblies...Extra framework folders: Done.
    Hiding strings...
    Renaming:  fields...Parameters...Properties...Events...Methods...Types...Done.
    Saving assemblies...Done.
    Writing log file...Done.
    Completed, 10.76 secs.
    Copying file from "/Users/user1/Documents/dev/project/src/MyProject.Android/bin/Debug/MyProject.dll" to "/Users/user1/Documents/dev/project/src/MyProject.Android/obj/Debug/android/assets/MyProject.dll".

However, when the app does run, it immediately crashes upon startup with:

System.IO.FileNotFoundException
Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.

Any ideas what's wrong with my configuration?

xamarin.android

obfuscation

obfuscar

android-obfuscation

0 Answers

Your Answer

Accepted video resources