Search code examples
c#androidxamarin.androidobfuscationnet-reactor

How to use .Net Reactor obfuscated dll of Xamarin Android APK


I am new to Xamarin Android. I have created an App using Visual Studio 2015 Community Edition. I have set the Solution Configuration to Release.

For obfuscation I used .Net Reactor.

This is how I tried to obfuscate

1: Once I build the App, I will go to Bin\Release folder

2: Obfuscate the App.dll

3: Replace the original dll with obfuscated dll in Bin\Release, Obj\Release and Obj\Release\assemblies

4: Go to Tools->Android->Publish

However when I tried to publish the obfuscated dll will be replaced by original dll.

So what I am doing wrong ? Do I have to manually pack the apk file. If that is the case how can I do that?


Solution

  • 1) Publish not obfuscated an application .apk, rename it to .zip.

    2) Move from it the file Mono.Android.dll from the folder "assemblies" into the folder YourProjectName\bin\Release.

    3) Create a new .NET Reactor project, set the right settings (uncheck Anti ILDASM, also the obfuscation process renames a fields that is used in reflection or serialization. To avoid crash of app, should set the exclusions for ignore some types or methods.). Save this project file into YourXamarinFolder\YourProjectName\bin\Release.

    4) Create the file obfuscate_android.bat, insert here the code:

     "C:\Program Files (x86)\Eziriz\.NET Reactor\dotNET_Reactor.exe" -project "NET_Reactor_Project_Name.nrproj"
      copy "YourProjectName_Secure\YourProjectName.dll" "YourProjectName.dll"
      DEL "YourProjectName_Secure\*.dll" "YourProjectName_Secure\*.pdb" /q
    

    Move this file into YourProjectName\bin\Release.

    5) Unload your Xamarin project and edit YourProjectName.csproj Find the next block:

    <PropertyGroup Condition = " '$ (Configuration) | $ (Platform)' == 'Release | AnyCPU'">
    <! -- Insert here the link to obfuscate_android.bat -->
    <PostBuildEvent>obfuscate_android.bat </ PostBuildEvent>
     </ PropertyGroup>
    

    6) Save all and Reload project

    7) Run Publish.