Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Could not load assembly Xamarin.Android.Support.Fragment (Xamarin.Forms 2.5)

Hi,

I tried to upgrade to latest release of Xamarin.Forms v2.5.0.77107 (was before on v2.4.0.74863). It works properly for my iOS and shared projects but compilation fails for my Android project:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2,2): Error: Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Xamarin.Android.Support.Fragment, Version=1.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Xamarin.Android.Support.Fragment.dll'
  at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference reference, Mono.Cecil.ReaderParameters parameters) [0x00099] in /Users/builder/data/lanes/5147/c2a33d8e/source/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:220 
  at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference reference) [0x00000] in /Users/builder/data/lanes/5147/c2a33d8e/source/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:170 
  at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver resolver, System.Collections.Generic.ICollection`1[T] assemblies, Mono.Cecil.AssemblyDefinition assembly, System.Boolean topLevel) [0x0015c] in <593a6fd557984367bb21e275d0fa0659>:0 
  at Xamarin.Android.Tasks.ResolveAssemblies.Execute (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver resolver) [0x0019c] in <593a6fd557984367bb21e275d0fa0659>:0  (LionsBase.Droid)

The Package section of my project does not have any reference to Xamarin.Android.Support.Fragment and if I try to add it manually, I get exception:

Could not install package 'Xamarin.Android.Support.Fragment 26.1.0.1'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v6.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Tried to choose an older release (24 or so) and error is similar.

My project is targeting Android 5.0 (API level 21) up to Android 7.0 (API level 24).

Tried to raise the maximum to Android 7.1 (API level 25) but it does not help.

Best Answer

  • XavierPerseguersXavierPerseguers CHMember ✭✭✭
    Accepted Answer

    Try manually changing the dependency in .csproj:

    -    <TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
    +    <TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
    

    I could successfully recompile by doing that:

    1. Create a blank new Forms project
    2. Add 1 by 1 each package I used in the real project
    3. Compile at each step to ensure it still works
    4. Finally compare .csproj, alter corresponding package definitions and copy packages.config

    Just had to get rid of Google Messaging (temporary) since I did not compile anymore and one should officially move to Firebase Cloud Messaging anyway.

Answers

  • WildSalmonWildSalmon FRMember ✭✭

    Hi @XavierPerseguers !

    I've been experiencing same behaviour while updating my Android project to the latest version. I went to solve this by downgrading to v2.4.0.74863.

    Hope you can make this work while their teams work on this issue !

    Cheers

  • ChannamydurChannamydur USMember
    edited November 2017

    I have been getting the same error on my windows computer

  • XavierPerseguersXavierPerseguers CHMember ✭✭✭

    Problem is still not solved after upgrading to newly-released Xamarin.Forms v2.5.0.91635, even if I change my project to target Android 8.0 (API Level 26).

  • XavierPerseguersXavierPerseguers CHMember ✭✭✭

    Tried something, without luck: Under Android's project properties > Build > General, Target framework was Android 6.0 (Marshmallow). After changing that to Android 7.0 (Nougat), I could add a reference to package Xamarin.Android.Support.Fragment, which in turns added references to:

    • MvvmCross.Platform
    • MvvmCross.Platform.Droid
    • MvvmCross.Core
    • MvvmCross.Droid
    • Xamarin.Android.Support.Annotations
    • Xamarin.Android.Support.Compat
    • Xamarin.Android.Support.Core.UI
    • Xamarin.Android.Support.Core.Utils
    • Xamarin.Android.Support.Media.Compat
    • MvvmCross.Droid.Support.Fragment

    It then fails compiling because MvvmCross.Binding is not found, let's add this too (this list of compatibility layers we need for Android is just getting totally insane anyway). Verdict: does not help, fails then with some weird Java exception.

  • DannyNDannyN USUniversity ✭✭

    I get this same problem as well upgrading to 2.5.0.91635. Requires fragment package but I can't install it b/c of the monodroid version i'm on.

  • bytebuilderbytebuilder USMember ✭✭

    same problem here. please share when fixed!! :)

  • AlexvanMeertenAlexvanMeerten NLMember ✭✭

    Same problem here. Downgraded to 2.4.0.74863.

  • XavierPerseguersXavierPerseguers CHMember ✭✭✭

    Any idea?

  • raV720raV720 PLMember ✭✭

    Same here. According to https://bugzilla.xamarin.com/show_bug.cgi?id=60810 it is needed to use 23.3.0 version of support libraries, but for me it does not solve problem. Why the status of bug is RESOLVED ANSWERED?

  • XavierPerseguersXavierPerseguers CHMember ✭✭✭
    Accepted Answer

    Try manually changing the dependency in .csproj:

    -    <TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
    +    <TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
    

    I could successfully recompile by doing that:

    1. Create a blank new Forms project
    2. Add 1 by 1 each package I used in the real project
    3. Compile at each step to ensure it still works
    4. Finally compare .csproj, alter corresponding package definitions and copy packages.config

    Just had to get rid of Google Messaging (temporary) since I did not compile anymore and one should officially move to Firebase Cloud Messaging anyway.

  • YunusEfendiYunusEfendi IDMember

    The problem I found with XF 2.5 with Android targeting v7.1 (or higher) is that the app is increased 2mb+ and the size is really matter to me, I think it's because Xamarin Android Support. so for now I will stick to XF 2.4 until it's fixed.

  • AmirImamAmirImam USMember ✭✭

    Now I have the same problem, and I don't know what to do

  • DonCB2BDonCB2B USMember ✭✭✭

    tried change target to 7.1, still didn't rebuild. Same error

    Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Xamarin.Android.Support.Fragment, Version=1.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?

  • ZoliZoli NLMember ✭✭✭

    Me too, still same error.
    is set to 7.1 on both GUI and .csproj file (done by IDE automatically after installing Andoroid SDK 7.1)

  • uwantfriesuwantfries GBBeta ✭✭

    Also got this after refreshing various things (forms and nugets)

  • ThomasLoidoltThomasLoidolt ATMember ✭✭

    Any solutions?

  • XamITXamIT USMember ✭✭
    edited March 2018

    Hi All, I had the same problem and addressed it using the following steps [Visual Studio on PC v15.6.1]-
    1. In android studio install / update the platform sdks for API level 26, 27 and P.
    2. Close the android studio
    3. In VS -> Tools ->Android -> Android SDK Manager make sure your have selected / installed platform sdk for your corresponding needs of the API 25,26, 27, [P?]
    4. In the VS Package Manager Console -
    4.1. run update-package reinstall (this will assure your current nuget package (in my case it was 26.x.x.x)
    4.2 at the VS solution , right click "Manage NuGet Packages for Solution"
    4.3 update packages manually by selecting all of the available updates
    4.4 using windows explorer confirm the installation of the packages in the packages folder inside the solution directory

    Give it a try...

    This will take you to the level of building your app and to deploy independently.
    The debug / deployment is still failing for me.

    VS is not able to attached my build to the debugger [here is my GitHub open issue that I have opened 2 days ago - https://github.com/xamarin/xamarin-android/issues/1392]

  • LeojetniopalLeojetniopal CAMember

    @AlexvanMeerten said:
    Same problem here. Downgraded to 2.4.0.74863.

    Had to downgrade too, lame...

  • VictorChelaruVictorChelaru USMember ✭✭

    To keep the thread alive, just wanted to add that this problem still occurs on Visual Studio 15.6.3. This really needs to be solved...

  • amirvenusamirvenus USMember ✭✭✭

    I had the same problem after updating some nuget packages and after all, I removed one line from the csproj and it worked!
    <Error Condition="!Exists('..\packages\Xamarin.Android.Support.Core.UI.25.4.0.2\build\MonoAndroid70\Xamarin.Android.Support.Core.UI.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Android.Support.Core.UI.25.4.0.2\build\MonoAndroid70\Xamarin.Android.Support.Core.UI.targets'))" />

  • ellix4uellix4u USMember ✭✭

    Check your solution explorer and make sure that your xamarin.form project is reference in the android/ios/UWP project and it doesn't show a yellow icon like the this image

Sign In or Register to comment.