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

[Bug] [Android] System.IO.FileNotFoundException when <BundleAssemblies>True</BundleAssemblies> #64

Closed
RadoslawKubas opened this issue Feb 24, 2020 · 82 comments · Fixed by #106
Assignees

Comments

@RadoslawKubas
Copy link

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

  1. Create new solution
  2. Upgrade Xamarin to 4.5.0.282-pre4
  3. Set:
<AndroidLinkMode>Full</AndroidLinkMode>
<AotAssemblies>True</AotAssemblies>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<EnableLLVM>True</EnableLLVM>
<BundleAssemblies>True</BundleAssemblies>
  1. 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
@jsuarezruiz
Copy link

@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:

<AndroidLinkMode>Full</AndroidLinkMode>
<AotAssemblies>True</AotAssemblies>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<EnableLLVM>True</EnableLLVM>
<BundleAssemblies>True</BundleAssemblies>

@VladislavAntonyuk
Copy link

I can reproduce it in release mode only

@danardelean
Copy link

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.

@PureWeen PureWeen transferred this issue from xamarin/Xamarin.Forms Feb 26, 2020
@Redth
Copy link
Member

Redth commented Feb 26, 2020

@danardelean can you be more specific about the error you are seeing? Please open a new issue with more details.

@RadoslawKubas
Copy link
Author

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
Copy link

mduchev commented 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
Copy link

mduchev commented 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:

  1. Open the solution
  2. Build the app in Release config
  3. Archive & Distribute it with a whatever signing identity you wish
  4. Install the signed apk into a phone
  5. 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

@tranb3r
Copy link

tranb3r commented 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
Copy link

nhdanh commented Mar 12, 2020

I have same problem

@tranb3r
Copy link

tranb3r commented Mar 12, 2020

Similar to #45 (which has been closed).
@moljac Could you please take a look ? This is quite serious...

@ognamala
Copy link

We have also observed this problem, which happens only in release mode and when Bundle Assemblies is set to true

@nhdanh
Copy link

nhdanh commented Mar 18, 2020

Will fix on new version ?

brminnick added a commit to brminnick/GitTrends that referenced this issue Mar 20, 2020
This is a temporary workaround for dotnet/android-libraries#64
@Adrien6
Copy link

Adrien6 commented Mar 23, 2020

Similar to #45 (which has been closed).
@moljac Could you please take a look ? This is quite serious...

+1

same issue for me.

@Policy56
Copy link

Policy56 commented Mar 24, 2020

Similar to #45 (which has been closed).
@moljac Could you please take a look ? This is quite serious...

I got the same issue, please take a look on it .. Can't update my app

@NicolasNMO
Copy link

Similar to #45 (which has been closed).
@moljac Could you please take a look ? This is quite serious...

Same for me, if you can see ? Thank.

@nhdanh
Copy link

nhdanh commented Mar 26, 2020

Same here 4.5.0.495 - still not working for me

@tranb3r
Copy link

tranb3r commented Mar 27, 2020

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

@moljac
Copy link
Contributor

moljac commented Mar 31, 2020

@mduchev

Your issue

java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.widget.FitWindowsFrameLayout" on path: DexPathList[[zip file 

looks like Xamarin.Forms one (it is in Essentials, but it is Forms one):
xamarin/Essentials#1198

So add proguard rule:

-keep public class androidx.appcompat.widget.FitWindowsFrameLayout

@moljac
Copy link
Contributor

moljac commented Mar 31, 2020

@mduchev Please report here if that helps. Thanks

@mattleibow
Copy link
Member

Hey folks! After looking at this, I think I have found out what is happening.

Basically, when using the <BundleAssemblies>, the build is making use of mkbundle to embed the dlls into the native file. And, it makes some assumptions: all files named *.resources.dll are satellite resource assemblies and it puts them into a sub folder. And coincidentally, the AndroidX dll happens to be named Xamarin.AndroidX.AppCompat.Resources.dll

This is what is happening now. We will get a solution/workaround ASAP for you folks.

Thanks for your patience and all the info/repros that helped us work this out.

For the folks interested in the code of mkbundle:
https://github.com/mono/mono/blob/9b4736d4c271e9d4e04cafa258ddd58961f1a39f/mcs/tools/mkbundle/mkbundle.cs#L1315-L1317

The logs will have something like this:

[mkbundle] C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Xamarin\Android\mkbundle.exe --dos2unix=false --nomain --i18n none --bundled-header --mono-api-struct-path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Xamarin\Android\\mkbundle-api.h" --style linux -c -o obj\Release\100\bundles\armeabi-v7a\temp.c -oo obj\Release\100\bundles\armeabi-v7a\assemblies.o -z obj\Release\100\android\shrunk\TestAndroidX.Android.dll obj\Release\100\android\shrunk\FormsViewGroup.dll obj\Release\100\android\shrunk\Java.Interop.dll obj\Release\100\android\shrunk\Mono.Android.dll obj\Release\100\android\shrunk\mscorlib.dll obj\Release\100\android\shrunk\System.Core.dll obj\Release\100\android\shrunk\System.dll obj\Release\100\android\shrunk\System.Numerics.dll obj\Release\100\android\shrunk\System.Xml.dll obj\Release\100\android\shrunk\TestAndroidX.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Activity.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Annotation.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.AppCompat.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.AppCompat.Resources.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Arch.Core.Common.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Arch.Core.Runtime.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.AsyncLayoutInflater.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Browser.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.CardView.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Collection.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.CoordinatorLayout.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Core.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.CursorAdapter.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.CustomView.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.DocumentFile.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.DrawerLayout.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Fragment.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Interpolator.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Legacy.Support.Core.UI.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Legacy.Support.Core.Utils.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Lifecycle.Common.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Lifecycle.LiveData.Core.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Lifecycle.LiveData.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Lifecycle.Runtime.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Lifecycle.ViewModel.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Loader.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.LocalBroadcastManager.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Media.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Print.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.RecyclerView.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.SavedState.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.SlidingPaneLayout.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.SwipeRefreshLayout.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.Transition.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.VectorDrawable.Animated.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.VectorDrawable.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.VersionedParcelable.dll obj\Release\100\android\shrunk\Xamarin.AndroidX.ViewPager.dll obj\Release\100\android\shrunk\Xamarin.Essentials.dll obj\Release\100\android\shrunk\Xamarin.Forms.Core.dll obj\Release\100\android\shrunk\Xamarin.Forms.Platform.Android.dll obj\Release\100\android\shrunk\Xamarin.Forms.Platform.dll obj\Release\100\android\shrunk\Xamarin.Forms.Xaml.dll obj\Release\100\android\shrunk\Xamarin.Google.Android.Material.dll obj\Release\100\android\shrunk\System.Net.Http.dll obj\Release\100\android\shrunk\System.Drawing.Common.dll obj\Release\100\android\shrunk\System.Runtime.Serialization.dll obj\Release\100\android\shrunk\System.ServiceModel.Internals.dll obj\Release\100\android\shrunk\Mono.Security.dll
[mkbundle stdout] Storing satellite assembly 'C:\Projects\Testing\TestAndroidX\TestAndroidX\TestAndroidX.Android\obj\Release\100\android\shrunk\Xamarin.AndroidX.AppCompat.Resources.dll' with name 'shrunk/Xamarin.AndroidX.AppCompat.Resources.dll'

@nhdanh
Copy link

nhdanh commented Apr 1, 2020

Will fix in release XF or VS ?

@moljac
Copy link
Contributor

moljac commented Apr 1, 2020

@nhdanh
This has nothing to do with XF or VS. It is AndroidX bindings and Xamarin.Android toolchain (very very deep under the hood)

@nhdanh
Copy link

nhdanh commented Apr 1, 2020

I only concern when my project will be fix this error :)

@mattleibow
Copy link
Member

@nhdanh most probably it will be fixed (worked around) in an AndroidX or Xamarin.Forms NuGet update. So not needing a wait for a VS update is good.

@moljac
Copy link
Contributor

moljac commented Jun 5, 2020

@EDMIStephen
When this bug was discovered we got feedback from several users how they use mkbundle and some where completely wrong for using mkbundle, but reasonable use case to be implemented/added. Some stated that "it is the cheapest obfuscator available" and mkbundle is NOT obfuscator. We cannot guarantee that code cannot be reversed engineered. OK it adds another layer of complexity, but it is not overly complex. If it is used for reducing size it can impact startup times.

We talked about docs too and that was mistake, but written long time ago.

It was fine to mention and warn users not to use mkbundle for what is not intended, but what to say if you keep doing it? Being vocal and demanding something you have been advised not to use/demand and demanding it to be done ASAP is also not professional, Add to that counting man hours spent on issues. Some users are forcing OOS maintainers to simply ignore them, but I don't want to do it for other helpful users. For example did you try nugets containing fixes for this issue? Some users did.

mkbundle was intended for self contained apps, but presenting it as security tool was wrong (not completelty wrong, but mostly). The same as cutting support for it, which in the end was not cut. We all make mistakes.

@tranb3r
Copy link

tranb3r commented Jun 5, 2020

@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.

@moljac
Copy link
Contributor

moljac commented Jun 5, 2020

@tranb3r

May I remind you that BundleAssemblies option used to be a Visual Studio Enterprise only feature, which means we paid for it !!

This was my argument for being against cancelling support of mkbundle or changing the code of it.

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.

The easiest part of this bug was fixing it on my side, but when this issue appeared I was working on other tasks too. We can go on and on what was right. There are users with the same arguments like yours who think that their problems (or wishes) have higher priority than yours.

Now as we communicate and I call for cooperation - I do test this issue. There are nugets with this hotfix. Did you try them? If I publish them and switch to another tasks I will not come back to this issue for a while, simply because of other tasks and users that are waiting.

@moljac
Copy link
Contributor

moljac commented Jun 5, 2020

Note: typeforwarding for some Xamarin.Forms apps might fail in some cases. Fix added in locally built nugets (link is above).

@tranb3r
Copy link

tranb3r commented Jun 5, 2020

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.

There are users with the same arguments like yours who think that their problems (or wishes) have higher priority than yours.

I'm not discussing priorities here. I'm challenging your process, which is obviously bad, if it makes you kill a feature instead of fixing a regression.

@moljac
Copy link
Contributor

moljac commented Jun 5, 2020

That is your opinion and you are completely entitled to it. The "sit and wait" process is not much better. Now you can continue with ad-hominem accusations via challenges about process or anything else, while ignoring my arguments (priorities).

Note: feature was not killed and regression is fixed.

And would you be so kind and propose few suggestions for improvements, please?

@simon10says
Copy link

@moljac , is the fixed only thru the link you provided above? Or will it be pushed thru the main, official channel (XF release)?

@moljac
Copy link
Contributor

moljac commented Jun 5, 2020

@simon10says

is the fixed only thru the link you provided above?

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.

Or will it be pushed thru the main, official channel (XF release)?

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.

@cleardemon
Copy link

Thank you @moljac, I'm sure most of us are very appreciative of yours and others' work 👍

@tranb3r
Copy link

tranb3r commented Jun 5, 2020

The "sit and wait" process is not much better.

May I remind you that I've tried to help you with this issue as much and as quickly as I could, by posting a repro project. This was more than 3 months ago.
Anyway, thank you for the fix.

@simon10says
Copy link

@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.

@moljac
Copy link
Contributor

moljac commented Jun 5, 2020

For those willing to test before publishing:

<PackageReference Include="Xamarin.Forms" Version="4.6.514" />

https://github.com/moljac/Samples.AndroidX/tree/master/nuget-local

@tranb3r
Copy link

tranb3r commented 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
Copy link
Contributor

moljac commented Jun 7, 2020

@tranb3r

I'm probably doing something wrong...

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:

  1. rename Xamarin.AndroidX.AppCompat.Resources to Xamarin.AndroidX.AppCompat.AppCompatResources version is 1.0.0.1

Or let nuget handle transitive dependencies:

Forms will pull everything in:

    <PackageReference Include="Xamarin.Forms" Version="4.6.514" />
    <PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />

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.

@tranb3r
Copy link

tranb3r commented Jun 8, 2020

@moljac
Here is my androidapp.csproj packagereferences (I've removed some custom nugets), if it can help.

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="4.6.514" />
    <PackageReference Include="Xamarin.AndroidX.Work.Runtime" Version="2.3.4.1" />
    <PackageReference Include="Xamarin.AndroidX.Migration" Version="1.0.6" />
    <PackageReference Include="Xamarin.AndroidX.Paging.Common" Version="2.1.2" />
  </ItemGroup>

For the rest of your explanation, sorry but I'm totally lost...

@moljac
Copy link
Contributor

moljac commented Jun 8, 2020

@tranb3r

For the rest of your explanation, sorry but I'm totally lost...

It is OK. I feel that way too. Ping me later if you want deeper info.

I would try several options:

  1. removing Xamarin.AndroidX.Migration completely
  2. change version of Xamarin.AndroidX.Migration to 1.0.0.1
  3. add explicitly Xamarin.AndroidX.AppCompat.AppCompatResources v 1.0.0.1

Please provide feedback.

Today after I publish 1.0.6.1 or 1.0.7 transitive dependency resolving will be easier.

@melimion
Copy link

melimion commented Jun 8, 2020

@tranb3r try this:

  • clean local nuget caches
  • disable all other nuget sources besides local with AndroidX packages
  • run "update-package -reinstall"

@moljac
Copy link
Contributor

moljac commented Jun 8, 2020

@melimion
Did updates from friday work for you?

@melimion
Copy link

melimion commented Jun 8, 2020

@moljac haven't tried yet, will try today

@moljac
Copy link
Contributor

moljac commented Jun 8, 2020

Nuget setup issue and related sample:

#111

@melimion
Copy link

melimion commented Jun 8, 2020

@moljac rebuilt app with new nugets- no issues

@moljac
Copy link
Contributor

moljac commented Jun 8, 2020

@melimion Thanks a lot for the feedback. Appreciated.

@tranb3r
Copy link

tranb3r commented Jun 8, 2020

@moljac
With new nugets, no more issues in my app.

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="4.6.514" />
    <PackageReference Include="Xamarin.AndroidX.Work.Runtime" Version="2.3.4.3" />
    <PackageReference Include="Xamarin.AndroidX.Migration" Version="1.0.6.1" />
    <PackageReference Include="Xamarin.AndroidX.Paging.Common" Version="2.1.2.1" />
  </ItemGroup>

Thanks !

@moljac
Copy link
Contributor

moljac commented Jun 9, 2020

@tranb3r NP (you re welcome).
Thank you for the feedback.

@EmilAlipiev
Copy link

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.

jonpryor pushed a commit to dotnet/android that referenced this issue Feb 28, 2023
Fixes: #7764

Context: d236af5
Context: dotnet/android-libraries#64 (comment)

.NET Android dropped support for `$(BundleAssemblies)`=True; see also
commit d236af5 and [a comment on dotnet/android-libraries#64][0]:

> 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.

However, this "dropping of support" was incomplete; setting it would
result in broken apps!

	% dotnet new android -n android-ba
	% cd android-ba
	% dotnet build -p:BundleAssemblies=true
	# run the app, or just look at the .apk contents
	% unzip -l bin/Debug/net7.0-android/*-Signed.apk | grep assem
	      660  02-03-2023 14:13   assemblies/rc.bin
	# Note: `assemblies/assemblies.blob` is not present, but is required!

Fix this by *removing* most usage of the `$(BundleAssemblies)` MSBuild
property as well as all the code affected by it.

  - Stop running bundle test apps on CI
  - Remove bundle unit tests
  - Remove the `CodeGen-MkBundle` project from the tests solution
  - Remove the `Xamarin.Android.MakeBundle-Tests` from the tests
    solution
  - Remove all native code (and configuration) related to mkbundle
  - Warn about `$(BundleAssemblies)` usage in .NET projects.
    A XA1035 warning will be emitted when `$(BundleAssemblies)`=True
    in .NET Android apps.

Preserve a couple of related properties in the `<BuildApk/>` and
`<GeneratePackageManagerJava/>` tasks, because they are still
used by the debugger targets from `xamarin/monodroid`.

[0]: dotnet/android-libraries#64 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet