AndroidX: [Bug] [Android] System.IO.FileNotFoundException when True
Description
After upgrade from Xamarin.Forms 4.4.0.991640 to 4.5.282-pre4 I noticed that when
<BundleAssemblies>True</BundleAssemblies>
app crash on start with exception
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.
My working setup for release in 4.4 is
<AndroidLinkMode>Full</AndroidLinkMode>
<AotAssemblies>True</AotAssemblies>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<EnableLLVM>True</EnableLLVM>
<BundleAssemblies>True</BundleAssemblies>
in 4.5 everything works fine only if
<AndroidLinkMode>Full</AndroidLinkMode>
<AotAssemblies>True</AotAssemblies>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<EnableLLVM>True</EnableLLVM>
<BundleAssemblies>False</BundleAssemblies>
Steps to Reproduce
- Create new solution
- Upgrade Xamarin to 4.5.0.282-pre4
- Set:
<AndroidLinkMode>Full</AndroidLinkMode>
<AotAssemblies>True</AotAssemblies>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<EnableLLVM>True</EnableLLVM>
<BundleAssemblies>True</BundleAssemblies>
- Run app on the real device
Expected Behavior
App starts.
Actual Behavior
App crash with System.IO.FileNotFoundException exception.
Basic Information
- Version with issue: 4.5.0.282-pre4
- Last known good version: 4.4.0.991640
- IDE: Visual Studio 2019
- Platform Target Frameworks:
- Android: Xamarin.Android 10.1
- Android Support Library Version: 28.0.0.03, AndroidX 1.1.0
- Nuget Packages:
- Affected Devices: all
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 82 (30 by maintainers)
Commits related to this issue
- Disabled BundleAssemblies This is a temporary workaround for https://github.com/xamarin/AndroidX/issues/64 — committed to brminnick/GitTrends by brminnick 4 years ago
- Use older Xamarin.Forms when bundling assemblies At least until https://github.com/xamarin/AndroidX/issues/64#issuecomment-606645412 is fixed. — committed to radekdoulik/xamarin-android by radekdoulik 4 years ago
- Use older Xamarin.Forms when bundling assemblies At least until https://github.com/xamarin/AndroidX/issues/64#issuecomment-606645412 is fixed. — committed to radekdoulik/xamarin-android by radekdoulik 4 years ago
- Use older Xamarin.Forms when bundling assemblies At least until https://github.com/xamarin/AndroidX/issues/64#issuecomment-606645412 is fixed. — committed to radekdoulik/xamarin-android by radekdoulik 4 years ago
- [XF test] Update nuget packages (#4592) To have XF test with up to date Xamarin.Forms package. Also update reference `.apkdesc` files. Use older XF for *Bundle* flavor, as it hits the known iss... — committed to xamarin/xamarin-android by radekdoulik 4 years ago
- [XF test] Update nuget packages (#4592) To have XF test with up to date Xamarin.Forms package. Also update reference `.apkdesc` files. Use older XF for *Bundle* flavor, as it hits the known iss... — committed to xamarin/xamarin-android by radekdoulik 4 years ago
- [Xamarin.Android.Build.Tasks] Add $(AndroidEnableAssemblyCompression) (#4686) Currently, Xamarin.Android supports compression of managed assemblies within the `.apk` if the app is built with [`$(Bu... — committed to xamarin/xamarin-android by grendello 4 years ago
- [Xamarin.Android.Build.Tasks] Add $(AndroidEnableAssemblyCompression) (#4686) Currently, Xamarin.Android supports compression of managed assemblies within the `.apk` if the app is built with [`$(Bund... — committed to xamarin/xamarin-android by grendello 4 years ago
- [Xamarin.Android.Build.Tasks] Remove support for mkbundle (#7772) Fixes: https://github.com/xamarin/xamarin-android/issues/7764 Context: d236af54538ef1fe62d0125798cdde78e46dcd8e Context: https://... — committed to xamarin/xamarin-android by grendello a year ago
Here is another repro project: TestAndroidX.zip
In debug mode, an image will be displayed on the main page. In release mode, the image is not displayed, because of the exception.
The exception is only happening with
<BundleAssemblies>True</BundleAssemblies>. It makes no difference whether R8 or Linker are enabled or not. I’m using XF 4.5.0. This exception can be easily reproduced on the emulator.Stack trace of the exception (no crash, it’s silent):
ImageElementManager: Error loading image: 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.File name: 'Xamarin.AndroidX.AppCompat.Resources, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'at Xamarin.Forms.Platform.Android.FileImageSourceHandler.LoadImageAsync (Xamarin.Forms.ImageSource imagesource, Android.Widget.ImageView imageView, System.Threading.CancellationToken cancellationToken)at Xamarin.Forms.Platform.Android.ImageViewExtensions.UpdateBitmap (Android.Widget.ImageView imageView, Xamarin.Forms.IImageElement newView, Xamarin.Forms.IImageElement previousView, Xamarin.Forms.ImageSource newImageSource, Xamarin.Forms.ImageSource previousImageSource)at Xamarin.Forms.Platform.Android.FastRenderers.ImageElementManager.TryUpdateBitmap (Xamarin.Forms.Platform.Android.IImageRendererController rendererController, Android.Widget.ImageView Control, Xamarin.Forms.IImageElement newImage, Xamarin.Forms.IImageElement previous)@15mgm15 asked:
The workaround is to not set
$(BundleAssemblies)=True.After internal discussion, we are strongly considering removing support for
$(BundleAssemblies)in .NET 5, as it increases on-device memory use and slows down app startup times.My comment is around the unprofessional message on the PR. It is fine to mention that is shouldn’t be used for obfuscation and that the documentation has been changed to further reflect this in another PR. But insinuating users are idiots is not appropriate especially when they are using a feature as documented and you have messages like this in visual studio.
The word obfuscation should also be completely removed from the Bundle assemblies section on this page because it has become clear that it provides no obfuscation. https://docs.microsoft.com/en-us/xamarin/android/deploy-test/release-prep/
Guys, do you really need 3 months to fix this? And week to test it?
Many users can’t upgrade to XF 4.5 and later because of this issue. And it looks like nobody cares.
@moljac rebuilt app with new nugets- no issues
@moljac , I might not agree on your attitudes on some of your replies, BUT BUT, as a technical person to another, I still like to thank you for your hard work.
You are the assignee to most of the issues. It seems like you are like a sweatshop child labor in a very very 3rd world country. It’s like Xamarin.Auth disappointment all over again. But, Cheer up. I’m not sure what’s your position or how high up you are, but it’s still better being a technical person and having these discussions than having to deal with the office/project politics. If you can’t handle the workload, let your boss know. This is not a hobbyist repository (is this?) where you can ask customer/user to “take it or leave it” (you didn’t explicitly, but your frustrated-attitude did). You never know which “big customer” Microsoft is trying to attract, but only to come here and get disheartened replies.
@simon10says
At this moment - yes. There are ready to press the button packages on CI, but it is not public, so I simply pushed those nugets to that repo, so external users could test.
XF team is already testing those nugets. OK. There were some improvements/fixes this morning, but they will be able to use them in few minutes. Then XF will publish XF nugets. When? I don’t know. Xamarin.Android ecosystem (AndroidX and Google.Play.Services with Firebase) has different cadence from Xamarin.Android core and Xamarin.Forms. I did some tests of XF apps this morning, to save time for XF team and it looks good, but they will test for sure.
I cannot promise anything for forms. Android parts will be released as soon as they confirm it.
@brminnick Thank you but this is off topic. We’re taking about the size of assemblies folder vs bundle.so file. The difference will be the same whether building an apk or an aab.
@mduchev
Your issue
looks like Xamarin.Forms one (it is in Essentials, but it is Forms one): https://github.com/xamarin/Essentials/issues/1198
So add proguard rule:
@moljac May I remind you that BundleAssemblies option used to be a Visual Studio Enterprise only feature, which means we paid for it !! So it’s not absurd for us to except a hot fix for this kind regression. Maybe the right thing to do would have been to release a hot fix first, and only after that, engage the discussion about the pros/cons of removing this feature, and the alternatives we would have.
This bug was opened more than one month ago, and it’s quite a serious regression. It’s also very easy to reproduce. Anybody please help. Thank you. @moljac @jsuarezruiz @mattleibow
I had/have the same problem and it is only in Release mode. Tried disabling Xamarin.AndroidX.AppCompat for the linker but I still got the problem.
Another problem with AndroidX (the stable versions) and XF 4.5 pre-release is that you cannot enable r8 (code shrinker) in release.
In the end I rolled back to the old support libraries and everything works.