Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not load file or assembly 'Xamarin.AndroidX.AppCompat.Resources' #45

Closed
Carl-Wen opened this issue Jan 15, 2020 · 12 comments
Closed
Assignees

Comments

@Carl-Wen
Copy link

Xamarin.Android Version (eg: 6.0):

Version: 10.1.3.7

Operating System & Version (eg: Mac OSX 10.11):

Mac OSX 10.15.2

Support Libraries Version (eg: 23.3.0):

28.0.3

Describe your Issue:

It works well until previous version a few days ago, but build error occurs today, then I upgrade dependency libraries to the newest, error changes to:

<PackageReference Include="Xamarin.AndroidX.Migration">
      <Version>1.0.0-preview05</Version>
      <Version>1.0.0-rc1</Version>
</PackageReference>
[MonoDroid] System.IO.FileNotFoundException: Could not load file or assembly 'Xamarin.AndroidX.AppCompat.Resources, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
[MonoDroid] File name: 'Xamarin.AndroidX.AppCompat.Resources, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
[MonoDroid]   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].Start[TStateMachine] (TStateMachine& stateMachine) [0x0002c] in <6b940a667a274fa48104ab71b2541709>:0 
[MonoDroid]   at Xamarin.Forms.Platform.Android.ResourceManager.GetFormsDrawableAsync (Android.Content.Context context, Xamarin.Forms.ImageSource imageSource, System.Threading.CancellationToken cancellationToken) [0x00033] in <a38b08ed6ae34fcca788cdc23b3fac01>:0 
[MonoDroid]   at Xamarin.Forms.Platform.Android.BottomNavigationViewUtils.SetMenuItemIcon (Android.Views.IMenuItem menuItem, Xamarin.Forms.ImageSource source, Android.Content.Context context) [0x00017] in <a38b08ed6ae34fcca788cdc23b3fac01>:0 
[MonoDroid]   at Xamarin.Forms.Platform.Android.BottomNavigationViewUtils.SetupMenu (Android.Views.IMenu menu, System.Int32 maxBottomItems, System.Collections.Generic.List`1[T] items, System.Int32 currentIndex, Google.Android.Material.BottomNavigation.BottomNavigationView bottomView, Android.Content.Context context) [0x001c8] in <a38b08ed6ae34fcca788cdc23b3fac01>:0 
[MonoDroid]   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <6b940a667a274fa48104ab71b2541709>:0 
[MonoDroid]   at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <78bc2a97e5be434ba8d7b494fe3c28fb>:0 
[MonoDroid]   at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <78bc2a97e5be434ba8d7b494fe3c28fb>:0 
[MonoDroid]   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <78bc2a97e5be434ba8d7b494fe3c28fb>:0 
[MonoDroid]   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.44(intptr,intptr)

Steps to Reproduce (with link to sample solution if possible):

Include any relevant Exception Stack traces, build logs, adb logs:

@moljac
Copy link
Member

moljac commented Jan 15, 2020

Why 2 versions? Did you try to remove one of them?

@moljac moljac self-assigned this Jan 15, 2020
@Carl-Wen
Copy link
Author

I am sorry, I mean upgrade to 1.0.0-rc1 from 1.0.0-preview05, I also tried 1.0.0-preview06 and it didn't work either.
All dependency libraries about androidx are below:

<ItemGroup>
    <PackageReference Include="Xamarin.AndroidX.Browser">
      <Version>1.0.0-preview02</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4">
      <Version>1.0.0-preview02</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Lifecycle.Extensions">
      <Version>2.0.0-preview02</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.MediaRouter">
      <Version>1.0.0-preview02</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Migration">
      <Version>1.0.0-rc1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.VectorDrawable.Animated">
      <Version>1.0.0-preview02</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Work.Runtime">
      <Version>2.0.1-preview02</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.ExifInterface">
      <Version>1.1.0-preview06</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Google.Android.Material">
      <Version>1.1.0-preview06</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.AppCompat.Resources">
      <Version>1.1.0-preview06</Version>
    </PackageReference>
  </ItemGroup>

@moljac
Copy link
Member

moljac commented Jan 17, 2020

@Carl-Wen

Did you manually write this code snipett:

<PackageReference Include="Xamarin.AndroidX.Migration">
      <Version>1.0.0-preview05</Version>
      <Version>1.0.0-rc1</Version>
</PackageReference>

?

Try removing <Version>1.0.0-preview05</Version>

@moljac
Copy link
Member

moljac commented Jan 20, 2020

@Carl-Wen
Can you provide minimal repro sample please? I use Xamarin.AndroidX.AppCompat.Resources in 20+ samples and was not able to reproduce this issue.

... or maybe provide exact steps how to reproduce this issue.

@Carl-Wen
Copy link
Author

Carl-Wen commented Jan 21, 2020

@moljac Now I replace AndroidX with support libraries, I did reproduce it with other projects. But it works with below config a few days ago, I try to upgrade all libraries to the newest, but it isn't work either:

   <ItemGroup>
     <PackageReference Include="Xamarin.AndroidX.Browser">
       <Version>1.0.0-preview02</Version>
     </PackageReference>
     <PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4">
       <Version>1.0.0-preview02</Version>
     </PackageReference>
     <PackageReference Include="Xamarin.AndroidX.Lifecycle.Extensions">
       <Version>2.0.0-preview02</Version>
     </PackageReference>
     <PackageReference Include="Xamarin.AndroidX.MediaRouter">
       <Version>1.0.0-preview02</Version>
     </PackageReference>
     <PackageReference Include="Xamarin.AndroidX.Migration">
       <Version>1.0.0-preview05</Version>
     </PackageReference>
     <PackageReference Include="Xamarin.AndroidX.VectorDrawable.Animated">
       <Version>1.0.0-preview02</Version>
     </PackageReference>
     <PackageReference Include="Xamarin.AndroidX.Work.Runtime">
       <Version>2.0.1-preview02</Version>
     </PackageReference>
     <PackageReference Include="Xamarin.AndroidX.ExifInterface">
       <Version>1.1.0-preview06</Version>
     </PackageReference>
     <PackageReference Include="Xamarin.Google.Android.Material">
       <Version>1.0.0-preview02</Version>
     </PackageReference>
   </ItemGroup>

@Nikituh
Copy link

Nikituh commented Jan 21, 2020

I would like to point out that I was also experiencing this issue, tried everything, without any avail. It has something to do with older project configurations. For Example, the old project did not have packages.config, various differences in the .csproj file.

The solution I found was to create a new project, add all the same dependencies, copy over all the code and voilà, unable to reproduce the issue.

@moljac
Copy link
Member

moljac commented Feb 2, 2020

Yes. Older stale projects can produce issues.

General guidelines:

  1. Migrate from packages.config to <PackageReference />

    Visual Studio for Windows has option for migration.

  2. Update all packagest to latest versions and test application

    Manage NuGet packages for Solution in Visual Studio for Windows can consolidate all packages for
    solution.

  3. Change options for Android application (all configurations) [TODO]

    1. aapt2

    2. d8

    3. r8

  4. Add Xamarin.AndroidX.Migration package to the Android application and rebuild.

  5. Fix issues reported by migration package (packages)

    In Visual Studio for Windows unload project and edit project file (*.csproj) by adding code snippet
    from migration package error.

    In Visual Studio for Mac unloading is not necessary - project files can be edited directly.

  6. Save, load/reload and rebuild application

    This step will most likely fail with numerous errors due to source code not being migrated (namespaces,
    fully qualified typenames).

  7. Fix source code (build errors) from step 5.

    This is manual step where Android.Support namespaces and [fully qualified] typenames must be replaced
    with AndroidX counterparts. Use tooltips available in both IDEs (Visual Studio for Windows and Mac).

    Do not forget migrating Android.Support packagenames in layout files (*.axml). Failing to do so will
    cause runtime errors (inflation of binary XML file).

    Mapping file (for search and replace):

    https://github.com/xamarin/AndroidX/blob/master/mappings/androidx-mapping.csv

also here

xamarin/XamarinAndroidXMigration#34

@moljac
Copy link
Member

moljac commented Feb 2, 2020

Closing this one

@moljac moljac closed this as completed Feb 2, 2020
@DevEddy
Copy link

DevEddy commented Mar 3, 2020

For me this issue only happens when I add the following configurations to my Android.csproj...

    <EnableLLVM>true</EnableLLVM>
    <AotAssemblies>true</AotAssemblies>
    <BundleAssemblies>true</BundleAssemblies>

-- Eddy

@nhdanh
Copy link

nhdanh commented Mar 12, 2020

I get error when build release, I just add Xamarin.AndroidX.Migration package. When I set true, it crash with error System.IO.FileNotFoundException: Could not load file or assembly 'Xamarin.AndroidX.AppCompat.Resources

I set fakse. My App Ok. How to resolve with option BundleAssemblies is true.

@nhdanh
Copy link

nhdanh commented Mar 26, 2020

Same here 4.5.0.495 - still not working for me

@mattleibow
Copy link
Contributor

Thanks for your patience folks.
We believe we have located the issue #64 (comment)

If you have any other discussion, please make comments on that issue so we can track it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants