Building release version for android failed

SuperwayneSuperwayne USMember
edited August 2014 in Xamarin.Android

I tried to build a release version of my Xamarin.Forms shared project for android to show it to someone. But it resulted in a exception:

C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(5,5): Error MSB4018: The "LinkAssemblies" task failed unexpectedly.
Xamarin.Android.XamarinAndroidException: error XA2006: Reference to metadata item 'Android.Text.InputTypes Android.Widget.SearchView::get_InputType()' (defined in 'Xamarin.Forms.Platform.Android, Version=1.2.2.0, Culture=neutral, PublicKeyToken=null') from 'Xamarin.Forms.Platform.Android, Version=1.2.2.0, Culture=neutral, PublicKeyToken=null' could not be resolved.
at Xamarin.Android.Diagnostic.Error(Int32 code, String message, Object[] args)
at Xamarin.Android.Tasks.LinkAssemblies.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext() (MSB4018) (Donner-Wetter.Android)

If I press "Go to" It shows this:

<Target Name="_LinkAssemblies"
  DependsOnTargets="_ResolveAssemblies;_CreatePackageWorkspace;_ResetLinkingFlag"
  Condition="'$(AndroidLinkMode)' != 'None'"
  Inputs="$(MSBuildAllProjects);@(ResolvedAssemblies->'$(MonoAndroidIntermediateAssemblyDir)%(TargetPath)%(Filename)%(Extension)')"
  Outputs="$(_AndroidLinkFlag)">
    <LinkAssemblies
      UseSharedRuntime="$(AndroidUseSharedRuntime)"
      MainAssembly="$(MonoAndroidIntermediateAssemblyDir)$(TargetFileName)"
      OutputDirectory="$(MonoAndroidIntermediateAssetsDir)"
      I18nAssemblies="$(MandroidI18n)"
      LinkMode="$(AndroidLinkMode)"
      LinkSkip="$(AndroidLinkSkip)"
      LinkDescriptions="@(LinkDescription)"
      ResolvedAssemblies="@(ResolvedAssemblies->'$(MonoAndroidIntermediateAssemblyDir)%(TargetPath)%(Filename)%(Extension)')" />

  <!-- We have to use a flag instead of normal outputs because linking can delete unused assemblies -->
  <Touch Files="$(_AndroidLinkFlag)" AlwaysCreate="true" />

</Target>

I just clicked the play button in Xamarin Studio with "release" and my andoird phone selected.

It's not a problem at the moment because I can use a debug version. But it would be one, if this occurs when I want to publish the app..

Is there anything I have to regard for a release build?

«1

Posts

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    Under the project properties-> Android Build->Linker... what is your Linker behavior set to?

    Try to set it to "Link SDK assemblies only"

  • SuperwayneSuperwayne USMember

    It was already set to "Link SDK assemblies only"

    As far as I can remember I haven't changed any settings except the start project and the needed androird versions.

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    You might want to remove the Xamarin.Forms NuGet package and add it back in and see if that helps it at all?

  • SuperwayneSuperwayne USMember

    Hmm that seem to help. I ran Xamarin Studio as administrator so it could successfully remove Xamarin.Forms (without admin rights it couldn't delte Xamarin.Forms.Task.dll) and added it again but I still get the same error.
    I tried to build a sample project (Xuzzle) and it worked.

  • I am also getting this same error. Have tried to remove and add back in the xamarin.forms nuget package and I still have the same problem.

  • KaiFriisKaiFriis NOMember ✭✭

    Me too. Debug works, however release fails with this error.

  • SuperwayneSuperwayne USMember

    If I set "Don't link" in the options for release build it works. But I think thats not the best solution since that would mean the app needs more space..

  • I'm affected by this issue too. Setting to "Don't Link" in the options for release build allows build to succeed, but build size is large. 7.56 MB for the iOS Release .ipa compared to a whopping 31.76 MB android .apk size (android Release build set to "Don't link").

  • BobBanksBobBanks USMember, University ✭✭
    edited September 2014

    I have the same issue and it may have started when I added Xamarin Forms Labs. Anyone else also using Labs?

    UPDATE: Removing Labs didn't fix the issue.

  • BobBanksBobBanks USMember, University ✭✭

    Solution is here: https://forums.xamarin.com/discussion/17929/error-executing-task-linkassemblies-for-android-release-build

    This is a bug in the latest version of Xamarin.Forms when compiled for API level 15 or less. It will be fixed in the next release. For now you can make sure you are targeting the latest android release (make sure you have the sdk's installed). API 14 support will be restored very soon.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Hi, I've this problem building for release. I've
    MinimumAndroidVersion= 4.2 (api17)
    targetAndroidVersion=Automatic use target (4.2 jellybean)

    C:\Program Files\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(5,5): Error MSB4018: errore imprevisto dell'attività "LinkAssemblies".
    Xamarin.Android.XamarinAndroidException: error XA2006: Reference to metadata item 'System.Void Android.Widget.AbsListView::SetSelectionFromTop(System.Int32,System.Int32)' (defined in 'Xamarin.Forms.Platform.Android, Version=1.3.3.0, Culture=neutral, PublicKeyToken=null') from 'Xamarin.Forms.Platform.Android, Version=1.3.3.0, Culture=neutral, PublicKeyToken=null' could not be resolved. ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void Android.Widget.AbsListView::SetSelectionFromTop(System.Int32,System.Int32)
    in Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
    in Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
    in Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
    in Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
    in Mono.Linker.Steps.MarkStep.ProcessQueue()
    in Mono.Linker.Steps.MarkStep.Process()
    in Mono.Linker.Steps.MarkStep.Process(LinkContext context)
    in Mono.Linker.Pipeline.Process(LinkContext context)
    in MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
    in Xamarin.Android.Tasks.LinkAssemblies.Execute()
    --- Fine della traccia dello stack dell'eccezione interna ---
    in Xamarin.Android.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args)
    in Xamarin.Android.Tasks.LinkAssemblies.Execute()
    in Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
    in Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext() (MSB4018) (Geco.Android)

  • TheRealJasonSmithTheRealJasonSmith USXamarin Team Xamurai

    @AlessandroCaliaro your problem is that you need to set the TargetAndroidVersion to 21 (and the compile version if you have that). Make sure your Android SDK is fully up to date. Xamarin.Forms needs the API 21 build chain (still supports back down to API 14 if you want).

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    @TheRealJasonSmith I've updated the Android SDK and them XS.
    With these updates, now I have a problem with "Fody" package.

    D:\Documenti\software\CSharpApp\ACaliaro\Crossware\Geco\Geco\packages\Fody.1.27.0\build\Fody.targets(5,5): Error MSB4044: all'attività "Fody.WeavingTask" non è stato assegnato un valore per il parametro obbligatorio "DefineConstants". (MSB4044) (Geco)

    Sorry, it's in italian.
    Is this problem depending by XS updates or Android updates?
    Alessandro

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    This problem is only in Release mode.

  • MichaelRidlandMichaelRidland AUInsider, University ✭✭✭
    edited February 2015

    Hi

    I've made all those change, but Unfortunately Im still having the same issue.
    packages/Fody.1.27.0/build/Fody.targets: Error: Error executing task Fody.WeavingTask: Required property 'DefineConstants' not set.

    Anymore ideas?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    @TheRealJasonSmith have solved the "Fody" problem for me.
    @TheRealJasonSmith , can you post your solution?
    Thanks

  • I am also facing the same issue in Release mode. And setting the SDK version to 21 doesnt resolve the problem.
    Here is the dump of the error.
    /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Error executing task LinkAssemblies: error XA2006: Reference to metadata item 'System.Void Android.Widget.AbsListView::SetSelectionFromTop(System.Int32,System.Int32)' (defined in 'Xamarin.Forms.Platform.Android, Version=1.3.4.0, Culture=neutral, PublicKeyToken=null') from 'Xamarin.Forms.Platform.Android, Version=1.3.4.0, Culture=neutral, PublicKeyToken=null' could not be resolved. (WorklightSample.Android)

  • DavidTavarezDavidTavarez DOMember ✭✭✭

    Same problem here.

  • SrihariKulkarniSrihariKulkarni INMember ✭✭

    @TheRealJasonSmith @NishAnil
    yup. happening only in release mode.. on a Mac as well as a Windows environment. Is System.Void Android.Widget.AbsListView::SetSelectionFromTop() not supported any more? We are not explicitly calling this in the app code. .

    C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(5,5): Error MSB4018: The "LinkAssemblies" task failed unexpectedly.
    Xamarin.Android.XamarinAndroidException: error XA2006: Reference to metadata item 'System.Void Android.Widget.AbsListView::SetSelectionFromTop(System.Int32,System.Int32)' (defined in 'Xamarin.Forms.Platform.Android, Version=1.3.5.0, Culture=neutral, PublicKeyToken=null') from 'Xamarin.Forms.Platform.Android, Version=1.3.5.0, Culture=neutral, PublicKeyToken=null' could not be resolved. ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void Android.Widget.AbsListView::SetSelectionFromTop(System.Int32,System.Int32)
    at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
    at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
    at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
    at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
    at Mono.Linker.Steps.MarkStep.ProcessQueue()
    at Mono.Linker.Steps.MarkStep.Process()
    at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
    at Xamarin.Android.Tasks.LinkAssemblies.Execute()
    --- End of inner exception stack trace ---
    at Xamarin.Android.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args)
    at Xamarin.Android.Tasks.LinkAssemblies.Execute()
    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
    at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext() (MSB4018) (WorklightSample.Android)

  • BilalAkilBilalAkil AUMember

    Same problem here

  • johanksonjohankson SEInsider, University ✭✭

    Same here...

  • bartholmberg.2426bartholmberg.2426 USMember, University

    I'm having similar problems with the release build failing. I used the SDK manager to install Android 5.1 (API 22) and Android 5.0 - but this does not show up in VS12 as a build option (API Level 20 is still highest).

    In Xamarin Studio API Level 21 shows up, but I get a compile error saying it can't find the jar file for API 21. Did anyone find a work around? Not being able to generate a release build seems pretty bad...

  • SrihariKulkarniSrihariKulkarni INMember ✭✭

    This fixes the issue. But may not be an optimal solution for all
    http://stackoverflow.com/a/28929770/1386298

  • ApurvaGoyalApurvaGoyal USMember ✭✭

    I am having the same issue. Its a serious issue and I dont see any response from Xamarin team!

  • Kent.GreenKent.Green USXamarin Team Xamurai
    edited January 2018

    Edit

    Technically the basic information below is still correct in most respects, but the versions to use have been updated. See this doc for the most recent details: https://developer.xamarin.com/guides/xamarin-forms/getting-started/installation/#Android

    Old resolution

    Hi All,

    ===Most common cause of this issue===
    One thing I've noted is often a point of confusion for folks hitting this issue is getting mixed up between the "Target Android Version", "Target Framework Version" & "Minimum Android Version." These are actually 3 distinct settings that have to have proper values in order for the "Link SDK Assemblies" setting to work as expected/supported on an Xamarin.Forms Android project.

    Both of the "Target (etc.)" settings should be set to Xamarin.Android 5.0/API 21. Then (as others have noted) also having the "Minimum Android Version" to at least API 14. This is considered the "supported" configuration for the latest stable version of Xamarin.Forms.

    Now, if you can confirm you have all 3 of those settings as valid (4 if you count the "Link SDK Assemblies" setting, but that's not so much causing the issue as a requirement to end up hitting it); then that might be something we can investigate further.

    -

    ===Settings to confirm===
    Summary of the settings to confirm:

    1) Target Framework: Android 5.0
    2) Target Android Version: API 21
    3) Minimum Android Version: API 14 (or higher).

    For detailed steps to find & set all these settings correctly in Visual Studio or Xamarin Studio, please refer to the following guide: https://kb.xamarin.com/customer/portal/articles/1902736-why-does-my-android-build-fail-with-error-executing-task-linkassemblies-error-xa2006-

    Hope this helps!
    -Kent Green
    Customer Support

    -

    P.S. One last note (and because I'm long-winded) is that the Linker setting is per configuration; typically (and by default) the linker is active for a Release configuration, but not a Debug configuration; though you can change this manually. More information about the linker is available in these guides:

    Android: http://developer.xamarin.com/guides/android/advanced_topics/linking/
    iOS: http://developer.xamarin.com/guides/ios/advanced_topics/linker/
    Cross-Platform: http://developer.xamarin.com/guides/cross-platform/advanced/custom_linking/

  • LloydSummersLloydSummers USMember ✭✭

    I'm a new user to this software, and giving the trial a good try before moving onto other frameworks - I have to say that I appreciate what has worked for me from the community and support team above:

    For people like me who just want the quick steps:

    • Right click on the Android project, and select Options
    • Select Build > General and change the Target Framework to Android 5.0 Lollipop
    • Select Android Build > Linker (tab) and ensure it is set to Link SDK assemblies only
    • Select Android Application > And set Target Android Version to Android 5.0 (API Level 21)
    • Make sure you've installed API level 21 in Android SDK
    • Build your release package

    With that said, as someone working through a trial - I've found quite a few issues with Xamarin Forms. This looks like the only Xamarin way to have cross-platform UI elements without recoding manually for each platform, and it seems quite a few of these issues go back several years (this issue - in this specific case - has been going on for 7 months from what I read above with limited support from the Xamarin team until the end).

    As a trial user, I do worry that Xamarin may not be mature enough for me to "hop on board" just yet, as I'm only testing very basic functionality and already hitting these roadblocks. It's just my two cents and my concerns as a third party - please take them as you wish, ignore them if you like, or complain as you see fit.

    With that piece said, this particular issue is resolved for me using the steps above.

  • KeithRoweKeithRowe USMember

    Thanks all for the updates. @LloydSummers - great summary. It does seem that Android is the weaker link in Forms - I have had numerous issues in Android with things that did not give me problems in iOS.

  • SupreetSupreet USMember

    Thanks @KentGreen.7328 your post helped.

  • Jus I changed linking from "NONE" to "sdk and users assembly" and I ran my solution, and the issue has been solved. after that you can change "sdk and users assembly" to "NONE" and run your project without any issue.

  • manikantajmanikantaj USMember

    C:\Program Files\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(3,3): Error MSB4018: The "CheckProjectItems" task failed unexpectedly.

    System.IO.FileNotFoundException: Could not load file or assembly 'Xamarin.AndroidTools, Version=0.0.0.0, Culture=neutral, PublicKeyToken=87f7c026dcad9390' or one of its dependencies. The system cannot find the file specified.

    File name: 'Xamarin.AndroidTools, Version=0.0.0.0, Culture=neutral, PublicKeyToken=87f7c026dcad9390'

    at Xamarin.Android.Tasks.MandroidDaemon.CreateDaemon()

    at Xamarin.Android.Tasks.MandroidDaemon.get_StandardInput()

    at Xamarin.Android.Tasks.MandroidDaemon.SendCommand(Task task, String[] commands, Action`1 response)

    at Xamarin.Android.Tasks.MandroidDaemon.GetEdition(Task task)

    at Xamarin.Android.Tasks.CheckProjectItems.Execute()

    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()

    at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

    === Pre-bind state information ===

    LOG: DisplayName = Xamarin.AndroidTools, Version=0.0.0.0, Culture=neutral, PublicKeyToken=87f7c026dcad9390
    (Fully-specified)

    LOG: Appbase = file:///C:/Program Files/Xamarin Studio/bin/MSBuild/dotnet.4.0/

    LOG: Initial PrivatePath = NULL

    Calling assembly : Xamarin.Android.Build.Tasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.

    ===

    LOG: This bind starts in LoadFrom load context.

    WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().

    LOG: Using application configuration file: C:\Program Files\Xamarin Studio\bin\MSBuild\dotnet.4.0\MonoDevelop.Projects.Formats.MSBuild.exe.Config

    LOG: Using host configuration file:

    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.

    LOG: Post-policy reference: Xamarin.AndroidTools, Version=0.0.0.0, Culture=neutral, PublicKeyToken=87f7c026dcad9390

    LOG: The same bind was seen before, and was failed with hr = 0x80070002.

    (MSB4018)

    i got this error

  • manikantajmanikantaj USMember

    please solve this,i am new to this xamarin

  • YoussefAzaroualiYoussefAzarouali USMember ✭✭
    edited October 2016

    Any news regarding this issue? I have tried everything but still no solution. Why doesn't anybody from xamarin come with a working solution?

  • JoseMolinaJoseMolina USMember

    I had this same issue.

    Make sure you're not referencing Xamarin.iOS. That was my issue. After removing it I was able to build in Release mode.

  • By deleting resourcecache folder helped me. First you should close your a project in Xamarin Studio, VS

  • MarcoRinaldiMarcoRinaldi ITMember ✭✭

    @JoseMolina said:
    I had this same issue.

    Make sure you're not referencing Xamarin.iOS. That was my issue. After removing it I was able to build in Release mode.

    This is my same issue. An involuntary reference to Xamarin.iOS in the Android project.

    Thanks!

  • RobClotherRobClother GBUniversity ✭✭

    This is happening for me, every single time. And it is blocking me.

  • RobClotherRobClother GBUniversity ✭✭

    Error The "LinkAssemblies" task failed unexpectedly.
    System.NullReferenceException: Object reference not set to an instance of an object.
    at Mono.Linker.Steps.ResolveFromAssemblyStep.ProcessLibrary(LinkContext context, AssemblyDefinition assembly)
    at Mono.Tuner.CustomizeActions.ProcessUserAssembly(AssemblyDefinition assembly)
    at Mono.Tuner.CustomizeActions.ProcessAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at MonoDroid.Tuner.Linker.Run(Pipeline pipeline, LinkContext context)
    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
    at Xamarin.Android.Tasks.LinkAssemblies.Execute()
    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()

    I have turned Mono Shared Runtime off.

  • EL_PAPIEL_PAPI USMember ✭✭

    @Superwayne said:
    '$(MonoAndroidIntermediateAssemblyDir)%(TargetPath)%(Filename)%(Extension)')" Outputs="$(_AndroidLinkFlag)">
    '$(MonoAndroidIntermediateAssemblyDir)%(TargetPath)%(Filename)%(Extension)')" />

    annoying ................................ don't know what to do un-install - re-install package still the same.

  • dlopmentdlopment USMember ✭✭

    I'm getting error in my Forms app while building the android project.

    I use:

    Visual Studio Enterprise 2015 Update 3
    Xamarin.Forms V2.3.3.193
    Target Framework: "Use Latest Platform (Android 7.1)"
    Minimum Android version: API Level 21
    Target Android version: "Use Compile using SDK version"
    Android Options: Shared Runtime, Fast Deployment, Enable ProGuard,Debugger .Net (Xamarin), Linking SDK Only
    Xamarin for Visual Studio and Xamarin.Android latest version
    Android SDK Tools: 25.2.5
    Android SDK Platform-tools: 26
    Android SDK Build-tools: 26
    Android SDK-Platform: from Android 5.0.1 (API 21) to Android 8.0.0 (API 26)
    

    With this configuration everything works perfectly!!!

    But if I update Xamarin.Forms to:

    v2.3.4.224
    v2.3.4.231
    v2.3.4.247
    

    I'm getting this error:

    Severity Code Description Project File Line Suppression State
    Error The "LinkAssemblies" task failed unexpectedly.
    System.NullReferenceException: Object reference not set to an instance of an object.
    at Mono.Linker.Steps.ResolveFromAssemblyStep.ProcessLibrary(LinkContext context, AssemblyDefinition assembly)
    at Mono.Tuner.CustomizeActions.ProcessUserAssembly(AssemblyDefinition assembly)
    at Mono.Tuner.CustomizeActions.ProcessAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at MonoDroid.Tuner.Linker.Run(Pipeline pipeline, LinkContext context)
    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
    at Xamarin.Android.Tasks.LinkAssemblies.Execute()
    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
    at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() RSUI (MobileApps\RSUI) C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets 1569

  • TomKington.8033TomKington.8033 USMember
    edited June 2017

    Hi all,

    I had this problem after a recent upgrade to Xamarin Android v7.3.1.2. Turns out the 'System.Data.Portable.dll' in my Android project was causing problems for the linker (see below link). After removing it my Android App build fine in release mode (and removing the library has not caused any problems).

    https://bugzilla.xamarin.com/show_bug.cgi?id=57645

    Cheers,

    Tom

«1
Sign In or Register to comment.