You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] [Android] System.IO.FileNotFoundException when <BundleAssemblies>True</BundleAssemblies> #64
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.
I checked with latest stable 4.5.0.356 and same problem repeats. I tried to prepare an example, but the problem is that even in my main solution, I can't reproduce it locally. When building same commit with VS2019 Community 16.4.5 it seems to be fine, but with build on Microsoft App Center and publish to Google Play, all prepunch tests fails.
I am having the exact same issue. On DEBUG everything works fine. If I change the config to Release - the build passes, I can archive the app but as soon as the app starts, the app crashes with the same error.
Okay, so I managed to produce a sample project and I managed to narrow down the problem, but this time I got a different exception (but at the same time it is kind of similar). It turned out that it isn't due to the BundleAssemblies config. This happens as soon as we choose to use r8 for code shrinking, the app crashes.
Archive & Distribute it with a whatever signing identity you wish
Install the signed apk into a phone
Run the app
If we don't have any code shrinking, everything works fine and the app launches successfully. However, if we choose to use code shrinking (and r8 specifically), then the app crashes with the following exception:
Time Device Name Type PID Tag Message
03-02 15:53:09.701 HMD Global Nokia 6.2 Error 26021 AndroidRuntime Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.widget.FitWindowsFrameLayout" on path: DexPathList[[zip file "/data/app/com.companyname.demoandroidxcrash-Pdr5ZJ6GGM0LzJrOyKjpMA==/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.demoandroidxcrash-Pdr5ZJ6GGM0LzJrOyKjpMA==/lib/arm64, /data/app/com.companyname.demoandroidxcrash-Pdr5ZJ6GGM0LzJrOyKjpMA==/base.apk!/lib/arm64-v8a, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(Unknown Source:223)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(Unknown Source:4)
at androidx.appcompat.app.AppCompatDelegateImpl.initWindowDecorActionBar(Unknown Source:0)
at androidx.appcompat.app.AppCompatDelegateImpl.getSupportActionBar(Unknown Source:0)
at androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(Unknown Source:7)
at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(Unknown Source:4)
at crc6422feeebb19be5b6f.MainActivity.n_onCreate(Native Method)
at crc6422feeebb19be5b6f.MainActivity.onCreate(Unknown Source:0)
at android.app.Activity.performCreate(Activity.java:7323)
at android.app.Activity.performCreate(Activity.java:7314)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2930)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3085)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6745)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Force finishing activity com.companyname.demoandroidxcrash/crc6422feeebb19be5b6f.MainActivity
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)
Reacted by Mihail Duchev, Radosław Kubas, Brandon Minnick, Emil Alipiev and rayita
When using Xamarin.Forms 4.6.514 instead of 4.6.0.800, here is the error I get on building my android app:
7>C:\Users\bertr.nuget\packages\xamarin.androidx.migration\1.0.6\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error : Could not find 1 Android X assemblies, make sure to install the following NuGet packages:
7>C:\Users\bertr.nuget\packages\xamarin.androidx.migration\1.0.6\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error : - Xamarin.AndroidX.AppCompat.Resources
7>C:\Users\bertr.nuget\packages\xamarin.androidx.migration\1.0.6\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error : You can also copy-and-paste the following snippet into your .csproj file:
7>C:\Users\bertr.nuget\packages\xamarin.androidx.migration\1.0.6\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error :
I'm probably doing something wrong...
And by the way, I don't understand why the new version of Xamarin.AndroidX.Migration that is being published is 1.0.0.1, when I'm already using 1.0.6.
I don't think so. With more complex samples there might be such issues with transitive dependencies. In some cases I had to manually fix some dependencies by adding explicit dependencies.
Can you post your project file (*.csproj) for Android app only. (PackageReference items), please.
For now:
rename Xamarin.AndroidX.AppCompat.Resources to Xamarin.AndroidX.AppCompat.AppCompatResources version is 1.0.0.1
Was your app migrated to AndroidX before? If yes, then you don't need to migrate again. You'll need it if some library references (transitively) Android.Support then types are mapped on CIL level (Mono.Cecil).
I will need more time to explain Migration.
Xamarin.AndroidX.Migration 1.0.0.1 had to be published, because of the mappings in THAT moment. (There were different artifacts bound at that version) and that nuget carries mapping files.
Just simple explanation:
Check 1st config.json published on 20200214 it has 89 artifacts bound. Latest one with 1.0.6 was published on 20200506 it has 96 artifacts. If I would publish updates with version 1.0.6.1 or 1.0.7 there would be mappings for only 89 artifacts, so 7 missing and that would cause problems. When I bump the last published tag on 1.0.6.1 it will contain all artifacts and everything for the mappings. After next release and fixes it will be 1.0.7 or I will publish 1.0.6.1 as 1.0.7.
Activity
jsuarezruiz commentedon Feb 25, 2020
@RadoslawKubas Could you attach an example or review the attached one?
Issue9689.zip
I can't reproduce it. I am using Xamarin.Forms 4.5-pre4 and:
VladislavAntonyuk commentedon Feb 25, 2020
I can reproduce it in release mode only
danardelean commentedon Feb 25, 2020
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.
Redth commentedon Feb 26, 2020
@danardelean can you be more specific about the error you are seeing? Please open a new issue with more details.
RadoslawKubas commentedon Feb 28, 2020
I checked with latest stable 4.5.0.356 and same problem repeats. I tried to prepare an example, but the problem is that even in my main solution, I can't reproduce it locally. When building same commit with VS2019 Community 16.4.5 it seems to be fine, but with build on Microsoft App Center and publish to Google Play, all prepunch tests fails.
mduchev commentedon Mar 2, 2020
I am having the exact same issue. On DEBUG everything works fine. If I change the config to Release - the build passes, I can archive the app but as soon as the app starts, the app crashes with the same error.
mduchev commentedon Mar 2, 2020
Okay, so I managed to produce a sample project and I managed to narrow down the problem, but this time I got a different exception (but at the same time it is kind of similar). It turned out that it isn't due to the BundleAssemblies config. This happens as soon as we choose to use r8 for code shrinking, the app crashes.
Here is the demo project:
DemoAndroidXCrash.zip
Steps to reproduce:
If we don't have any code shrinking, everything works fine and the app launches successfully. However, if we choose to use code shrinking (and r8 specifically), then the app crashes with the following exception:
Time Device Name Type PID Tag Message
03-02 15:53:09.701 HMD Global Nokia 6.2 Error 26021 AndroidRuntime Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.widget.FitWindowsFrameLayout" on path: DexPathList[[zip file "/data/app/com.companyname.demoandroidxcrash-Pdr5ZJ6GGM0LzJrOyKjpMA==/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.demoandroidxcrash-Pdr5ZJ6GGM0LzJrOyKjpMA==/lib/arm64, /data/app/com.companyname.demoandroidxcrash-Pdr5ZJ6GGM0LzJrOyKjpMA==/base.apk!/lib/arm64-v8a, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(Unknown Source:223)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(Unknown Source:4)
at androidx.appcompat.app.AppCompatDelegateImpl.initWindowDecorActionBar(Unknown Source:0)
at androidx.appcompat.app.AppCompatDelegateImpl.getSupportActionBar(Unknown Source:0)
at androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(Unknown Source:7)
at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(Unknown Source:4)
at crc6422feeebb19be5b6f.MainActivity.n_onCreate(Native Method)
at crc6422feeebb19be5b6f.MainActivity.onCreate(Unknown Source:0)
at android.app.Activity.performCreate(Activity.java:7323)
at android.app.Activity.performCreate(Activity.java:7314)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2930)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3085)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6745)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Force finishing activity com.companyname.demoandroidxcrash/crc6422feeebb19be5b6f.MainActivity
tranb3r commentedon Mar 3, 2020
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)nhdanh commentedon Mar 12, 2020
I have same problem
tranb3r commentedon Mar 12, 2020
Similar to #45 (which has been closed).
@moljac Could you please take a look ? This is quite serious...
ognamala commentedon Mar 17, 2020
We have also observed this problem, which happens only in release mode and when Bundle Assemblies is set to true
nhdanh commentedon Mar 18, 2020
Will fix on new version ?
66 remaining items
tranb3r commentedon Jun 6, 2020
When using Xamarin.Forms 4.6.514 instead of 4.6.0.800, here is the error I get on building my android app:
7>C:\Users\bertr.nuget\packages\xamarin.androidx.migration\1.0.6\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error : Could not find 1 Android X assemblies, make sure to install the following NuGet packages:
7>C:\Users\bertr.nuget\packages\xamarin.androidx.migration\1.0.6\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error : - Xamarin.AndroidX.AppCompat.Resources
7>C:\Users\bertr.nuget\packages\xamarin.androidx.migration\1.0.6\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error : You can also copy-and-paste the following snippet into your .csproj file:
7>C:\Users\bertr.nuget\packages\xamarin.androidx.migration\1.0.6\buildTransitive\monoandroid90\Xamarin.AndroidX.Migration.targets(131,9): error :
I'm probably doing something wrong...
And by the way, I don't understand why the new version of Xamarin.AndroidX.Migration that is being published is 1.0.0.1, when I'm already using 1.0.6.
moljac commentedon Jun 7, 2020
@tranb3r
I don't think so. With more complex samples there might be such issues with transitive dependencies. In some cases I had to manually fix some dependencies by adding explicit dependencies.
Can you post your project file (
*.csproj) for Android app only. (PackageReferenceitems), please.For now:
Xamarin.AndroidX.AppCompat.ResourcestoXamarin.AndroidX.AppCompat.AppCompatResourcesversion is 1.0.0.1Or let nuget handle transitive dependencies:
Forms will pull everything in:
Was your app migrated to AndroidX before? If yes, then you don't need to migrate again. You'll need it if some library references (transitively) Android.Support then types are mapped on CIL level (Mono.Cecil).
I will need more time to explain Migration.
Xamarin.AndroidX.Migration 1.0.0.1 had to be published, because of the mappings in THAT moment. (There were different artifacts bound at that version) and that nuget carries mapping files.
Just simple explanation:
Check 1st
config.jsonpublished on 20200214 it has 89 artifacts bound. Latest one with 1.0.6 was published on 20200506 it has 96 artifacts. If I would publish updates with version 1.0.6.1 or 1.0.7 there would be mappings for only 89 artifacts, so 7 missing and that would cause problems. When I bump the last published tag on 1.0.6.1 it will contain all artifacts and everything for the mappings. After next release and fixes it will be 1.0.7 or I will publish 1.0.6.1 as 1.0.7.tranb3r commentedon Jun 8, 2020
@moljac
Here is my androidapp.csproj packagereferences (I've removed some custom nugets), if it can help.
For the rest of your explanation, sorry but I'm totally lost...
moljac commentedon Jun 8, 2020
@tranb3r
It is OK. I feel that way too. Ping me later if you want deeper info.
I would try several options:
Xamarin.AndroidX.MigrationcompletelyXamarin.AndroidX.Migrationto 1.0.0.1Xamarin.AndroidX.AppCompat.AppCompatResourcesv 1.0.0.1Please provide feedback.
Today after I publish 1.0.6.1 or 1.0.7 transitive dependency resolving will be easier.
melimion commentedon Jun 8, 2020
@tranb3r try this:
moljac commentedon Jun 8, 2020
@melimion
Did updates from friday work for you?
melimion commentedon Jun 8, 2020
@moljac haven't tried yet, will try today
moljac commentedon Jun 8, 2020
Nuget setup issue and related sample:
#111
melimion commentedon Jun 8, 2020
@moljac rebuilt app with new nugets- no issues
moljac commentedon Jun 8, 2020
@melimion Thanks a lot for the feedback. Appreciated.
tranb3r commentedon Jun 8, 2020
@moljac
With new nugets, no more issues in my app.
Thanks !
moljac commentedon Jun 9, 2020
@tranb3r NP (you re welcome).
Thank you for the feedback.
EmilAlipiev commentedon Jun 9, 2020
Sorry, late to the party but actually Xamarin team seems to be right. Bundle into native assemblies reduces size for apk but increases for aab. Here is what i found,
see in this SO post. https://stackoverflow.com/questions/62293367/xamarin-android-app-bundle-with-bundle-into-native-assemblies-increases-size-b
Let me know if you have similar experience.
[Xamarin.Android.Build.Tasks] Remove support for mkbundle (#7772)