I need to obfuscate some of my dlls before creating the .apk. I already had this running for a few years, but it seems like
the build process changed lately and it does not work anymore.
I have a target in my .csproj for the obfuscation:
<Target Name="Obfuscate" AfterTargets="_CopyIntermediateAssemblies" Condition="'$(Configuration)' == 'Release'"> <Exec Command="$(MSBuildProjectDirectory)\Obfuscate.bat $(MSBuildProjectDirectory)" WorkingDirectory="$(MonoAndroidLinkerInputDir)" /> </Target>
In the past the obfuscator worked in the bin\Release folder, but that folder doesn't contain all dependencies anymore.
After the obfuscation I used to copy the files to obj\Release\linksrc in order to get picked up by the linker.
I saw that obj\Release\90\linksrc does contain all the .dlls, so I changed the obfuscation to work in that folder instead
and copy the obfuscated files to bin\Release.
Now the obfuscation works, but the linker fails.
The "LinkAssemblies" task failed unexpectedly.\r Mono.Linker.MarkException: Error processing method: 'System.Threading.Tasks.Task`1<System.Boolean> RoyalMobileApps.XF.Helpers.LauncherBase::LaunchConnection(RoyalDocumentLibrary.RoyalConnection,Xamarin.Forms.ToolbarItem,System.Collections.Generic.Dictionary`2<System.String,System.String>)' in assembly: 'RoyalMobileApps.XF.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve RoyalMobileApps.XF.Helpers.LauncherBase/<LaunchConnection>d__1\r
I had obfuscation running before the linker in the past, but apparently this is a problem now, so I tried to start it
Now both obfuscation and linking works, but the apk contains the unobfuscated files.
I added to my Obfuscation.bat that the obfuscated files will be copied to obj\Release\90\android\assets where I also found all dlls.
Again obfuscation and linking works, but I get an error in GenerateJavaStubs:
The "GenerateJavaStubs" task failed unexpectedly.\r System.IO.FileNotFoundException: Could not load assembly 'netstandard, Version=184.108.40.206, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Perhaps it doesn't exist in the Mono for Android profile?\r File name: 'netstandard.dll'\r at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)\r at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference)\r at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)\r at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type)\r at Mono.Cecil.TypeReference.Resolve()\r at Java.Interop.Tools.Cecil.TypeDefinitionRocks.<GetTypeAndBaseTypes>d__1.MoveNext()\r at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)\r at Java.Interop.Tools.Cecil.TypeDefinitionRocks.IsSubclassOf(TypeDefinition type, String typeName)\r at Java.Interop.Tools.JavaCallableWrappers.JavaTypeScanner.AddJavaTypes(List`1 javaTypes, TypeDefinition type)\r at Java.Interop.Tools.JavaCallableWrappers.JavaTypeScanner.GetJavaTypes(IEnumerable`1 assemblies, IAssemblyResolver resolver)\r at Java.Interop.Tools.JavaCallableWrappers.TypeNameMapGenerator..ctor(IEnumerable`1 assemblies, Action`2 logger)\r at Java.Interop.Tools.JavaCallableWrappers.TypeNameMapGenerator..ctor(IEnumerable`1 assemblies, Action`2 logMessage)\r at Xamarin.Android.Tasks.GenerateJavaStubs.WriteTypeMappings(List`1 types)\r at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res)\r at Xamarin.Android.Tasks.GenerateJavaStubs.Execute()\r at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()\r at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
One last try was to start obfuscation
AfterTargets="_CopyIntermediateAssemblies" again and copy the files to obj\Release\90\android\assets too.
Unfortunately the linker failed with the same error I got above without copying the files to that folder.
So when should I run the obfuscator and where should it place the files?