Forum Xamarin.Android

Some dlls are not copied to bin/Release folder

MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

I'm trying to build the Android project of my Xamarin.Forms solution with msbuild:

set MSBuild="C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe"
%msbuild% RoyalMobileApps.XF.Android.csproj /p:Configuration=Release /t:PackageForAndroid

The build succeeds, the .apk has all needed dlls in its assemblies subfolder, but the bin\Release folder itself is missing many dlls. I try to run an obfuscator during the build, so I need those dependencies.

This all worked before but something in the build process seems to have changed.

I digged through the logfile and found this message for (at least some of) the missing dlls:

This reference is not "CopyLocal" because at least one source item had "Private" set to "false" and no source items had "Private" set to "true".

When searching for that message I found https://github.com/NuGet/Home/issues/1084. But that issue is for Windows and the workaround from there did not work for Android.

Any idea how I can enforce the CopyLocal for all dependencies?

Tagged:

Best Answer

  • MichaelRumplerMichaelRumpler AT ✭✭✭✭✭
    edited January 2019 Accepted Answer

    I got it now. I use the obj\Release\90\linksrc folder as WorkingDirectory of the obfuscator now. That folder contains all necessary files. My target changed to this:

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

    And with some adjustments in the Obfuscate.bat this works now.
    But now the linker fails. Well, one step at a time... :'(

Answers

  • YorkGoYorkGo CNMember, Xamarin Team Xamurai
    edited January 2019

    The build succeeds, the .apk has all needed dlls in its assemblies subfolder, but the bin\Release folder itself is missing many dlls

    What .dll are you missing, could you please elaborate a bit more? Did this issue happened on a blank project? If possible, would you mind sharing a basic demo that can reproduce the problem through online repo?

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭

    Some standard NuGet packages like Newtonsoft.Json, AndHUD and DevExpress.Mobile.Grid are missing.

    The problem is that I need to obfuscate my app. The obfuscator needs to read all dependencies.

    I run the obfuscator with an additional target in my .csproj file:

    <Target Name="Obfuscate" AfterTargets="_CopyIntermediateAssemblies" Condition="'$(Configuration)' == 'Release'">
      <Exec Command="D:\RoyalFamily\RoyalApplications\RoyalTS\Mobile\Android\RoyalTSD\Obfuscate.bat" WorkingDirectory="bin\Release" />
    </Target>
    

    This did work before, but now it fails because it can't find some dependencies in the bin\Release folder.

    [ERROR] Failed to resolve dependency of 'RoyalPasswords.BrowserExtensions.PCL.dll'.
    Exception: dnlib.DotNet.AssemblyResolveException: Could not resolve assembly: Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
       at dnlib.DotNet.Extensions.ResolveThrow(IAssemblyResolver self, IAssembly assembly, ModuleDef sourceModule) in d:\ConfuserEx_my_fork\dnlib\src\DotNet\IAssemblyResolver.cs:line 113
       at Confuser.Core.ConfuserEngine.Inspection(ConfuserContext context) in d:\ConfuserEx_my_fork\Confuser.Core\ConfuserEngine.cs:line 264
    

    I found all needed files in obj\Release\90\linksrc. Is this path constant or does the 90 vary? Is there a variable with it which I can use? The best would be if I could just set the WorkingDirectory to that variable when executing the obfuscator.

    This is my full app. As I even need to obfuscate it you do understand that I cannot give you the source.

  • MichaelRumplerMichaelRumpler ATMember ✭✭✭✭✭
    edited January 2019 Accepted Answer

    I got it now. I use the obj\Release\90\linksrc folder as WorkingDirectory of the obfuscator now. That folder contains all necessary files. My target changed to this:

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

    And with some adjustments in the Obfuscate.bat this works now.
    But now the linker fails. Well, one step at a time... :'(

  • YorkGoYorkGo CNMember, Xamarin Team Xamurai

    @MichaelRumpler , if you need our help about the linker problem, you could post a new issue. :)

Sign In or Register to comment.