-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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] iOS: On-Demand Resource Tag not available to be set #27213
Comments
You can probably try editing csproj directly and use build actions like this in an ItemGroup with a condition for iOS:
And see if it works. I have no real knowledge if it works, but at least you can try it out. |
All Build Actions that were available in Xamarin.iOS should still work, make sure to add a condition on them to only include them for the iOS platform when using single-project. If the issue then is that being not able to set these properties through the UI in Visual Studio, then this is something in the tooling. Otherwise, you state that you think this is a bug in .NET MAUI, but without any information about what you have tried, version information, a reproduction, logs or anything similar it will be pretty hard to verify that. Please provide any additional details for us to look at and we will gladly try to help if we can. |
@jfversluis the issue is the following: Based on the description here: https://learn.microsoft.com/en-us/dotnet/maui/android/asset-packs?view=net-maui-9.0#asset-packs-in-net-maui-apps MAUI Apps with .NET 9 now have the option for MauiAssets to be used as Android asset packs (the equivalent of iOS On-Demand Resources). However this does not reflect over to the iOS build even tho the If I now have both in my app, the "asset" is twice in the iOS *.ipa file (if the On-Demand Resource even works as the UI in VisualStudio has no option to set the Tag as it does in Xamarin.iOS / Xamarin.Forms applications). Also there is 0 documentation about the iOS On-Demand Resource except the official one from Apple and a few guides on the Internet how this has to be done on Xamarin.iOS. And there is even less for the new AssetPack part of MAUI .NET 9 even tho it is very likely that if I use this feature, I also want to use the very same on the other platform. So logically it already makes no sense at all, once again, that the added part to make this finally work on Android does not also include iOS even tho it has worked before. That's just inconsistant and bad. And I do not have the This is how it is on my Xamarin.Forms / iOS projects: https://i.imgur.com/ZsE3d1t.png And what did I try? I tried to add it manually in the *.csproj file. I tried every possible option I could imagine in VisualStudio. So basically I have now to write complex ItemGroup Conditions in the hope that it will build properly and work after manually editing the *.csproj file. It's baffling that MAUI and the associated tooling is still so unfinished that you can't even upgrade Xamarin.Forms projects without hourlong research and try&error. |
The thing is that Android apps have a maximum size of 200 MB (without asset packs) and iOS apps have a maximum size of 4 GB. It was much needed that at least install-time asset packs were implemented for Android (which can be 1.5 GB in size) that would increase the total app size limit to 4 GB on Android. 200 MB is so small that publishing even a medium-sized game in the Google Play Store requires the use of asset packs. The implementation of Play Asset Delivery asset packs in .NET 9 was great (thanks to @dellis1972) and it allowed us to stop using manual workarounds that were required for Xamarin.Forms apps (essentially building the asset packs manually using aapt2). I understand that implementing On-Demand resources for iOS has not been on very high priority for the .NET iOS / MAUI team, since the 4 GB app size limit is pretty high. Also, the implementation is platform-dependent, so whatever work the .NET for Android team did for Play Asset Delivery asset packs, can't be used by the .NET for iOS team. If you want to know if the old code from Xamarin.Forms still works, I'd suggest contacting the .NET for iOS team over here: https://github.com/xamarin/xamarin-macios It's true that things could be in a better shape, but I suggest that you try to contact the right people and perhaps find some solution to your problem that you can share with others that have the same problem. You can probably find emails of people responsible for .NET for iOS on GitHub and contact them directly, if need be, or you can leave an issue or start a discussion. |
@TommiGustafsson-HMP it already worked for iOS with Xamarin.iOS and Xamarin.Forms. It just makes no sense, once again, how they solved it here. No documentation at all on this topic. Weird *.csproj edits that may work or may not work. While there is a implementation available with .NET 9 that could just be used on both platforms. I agree, it was necessary and long overdue for Android. But there is no reason at all why the already working implementation of Xamarin.iOS and Xamarin.Forms seems to be not available and is not done in the same way as it is the same thing. And for your games reference: Who the hack would make games with MAUI? There are far better options available for that. |
We have a Xamarin.Forms / MAUI game here: We used Xamarin.Forms originally with SkiaSharp, because we needed to port the NetHack codebase to modern operating systems and it turned out after long research that Xamarin.Forms and .NET had the best interoperability with C code. You can read more about it in this article: https://github.com/hyvanmielenpelit/GnollHack/wiki/Mobile-Version-Development |
And just because you had a, probably giga niche, use case for it, thats the reason already working and existing stuff should be broken on the newer replacement framework? Yes makes sense. Espacially if similar functionality is added on another platform, it makes much sense that exclude the other platforms on a cross platform framework. That asset packs where not available before was due to Xamarin.Android. But now Xamarin.Android and Xamarin.iOS have this feature. So the reasoning excluding a platform should not exist. Espacially because this should be a very small thing. |
So the One option is to use the following in your csproj. There should be no reason to duplicate the Items as the <ItemGroup>
<MauiAsset Update="/Resources/Raw/*" AssetPack="installtime" ResourceTags="installtime" />
<!-- its iOS resource so we don't need assetpack on it -->
<MauiAsset Update="Platforms/iOS/Resources/*" ResourceTags="installtime" />
</ItemGroup> You can also limit the update to certain files via wildcards or specifying the actual specific path. <ItemGroup>
<MauiAsset Update="/Resources/Raw/*.mp4" AssetPack="installtime" ResourceTags="installtime" />
<MauiAsset Update="Platforms/iOS/Resources/*.mp4" ResourceTags="installtime" />
<MauiAsset Update="Platforms/iOS/Resources/mylargefile.txt" ResourceTags="foo" />
</ItemGroup> Granted that is not obvious how to do that from the IDE. We'd need to talk to the IDE teams to figure out how to expose the metadata on Here is a sample of what this code produces
Note it will pickup the ResourceTags attribute and do the right thing. |
@dellis1972 if it really works like this (will test this tomorrow), where is this documented? As I was not able to find anything about a ResourceTags attribute in the hours I thought I wasted on this topic. But if this is how it works, and if it really works, then it's exactly what I was looking for. |
@Sebastian1989101 its not documented for iOS or Android, as its how MSBuild works [1]. The "Metadata" (Attributes or Child Elements) are carried through to over ItemGroups when they are copied (for the most part). There is no code in the iOS or Android .Net (or Maui) Sdks which specifically looks at/for the To be honest, I know nothing about iOS, I didn't even know it supported OnDemand assets as my principal focus is Android. I changed the following code which is almost right from the blog post. <ItemGroup>
<MauiAsset Update="**\*.bank" AssetPack="installtime" />
</ItemGroup> to <ItemGroup>
<MauiAsset Update="**\*.bank" AssetPack="installtime" ResourceTags="installtime" />
</ItemGroup> and it worked as expected and placed all the ".bank" files in an OnDemand pack.😃 [1] https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-items?view=vs-2022#item-metadata |
@dellis1972 this part alone in the documentation would have been really helpful. However you said you tested it, but did it work? Because on my machine it's only placing empty files in the assetpack target location and trying to access them results in a error:
https://i.imgur.com/T8ddkBX.png For my test I just did the following: Added this to the *.csproj file:
And then added this to the Platforms/iOS/AppDelegate.cs file:
This should have resulted in a On-Demand Resource loaded on request. However this might be a issue with the debug build because as far as I remember, this issue was also there on Xamarin.Forms / Xamarin.iOS and got ignored in the classic Microsoft/Xamarin/MAUI way of handling issues. Edit: Yes, the same issue existed back in the days in Xamarin.Forms... well then I just hope it will work on a release build but thats something I can only test in a few days when I'm done converting my Forms app... xamarin/xamarin-macios#8026 |
as I said, I'm not an iOS person. All I know is the data ended up in this path |
Should be correct, I agree. But in my case the files are just empty that got created there through VisualStudio. And I assume empty files is not fully correct. ;) |
@rolfbjarne might be able to shed some light on that issue. |
@dellis1972 Is there actually a reason why the MAUI documentation differs from the official Android documentation regarding the size etc. of the AssetPacks? For example the MAUI documentation says there can only be one InstallTime AssetPack while this limit seems to not exist on the Android documentation. Also the Android documentations says up to 100 AssetPacks each 1.5GB max while MAUI says 50 with 2GB total. https://developer.android.com/guide/playcore/asset-delivery?hl=en https://support.google.com/googleplay/android-developer/answer/9859372#size_limits I assume that MAUI just tunnels it through Xamarin.Android which just wraps the native stuff? So I assume the Android documentation limits are the correct ones? Same for iOS with the iOS documentation. |
@Sebastian1989101 I have no idea. I didn't write those docs, only the blog post. |
@dellis1972 is there any sample for InstallTime AssetPacks? I can see them if I build a publish package but when debugging on the simulator, the asset pack is nowhere to be found. And yes, I have included the part from "Test asset packs locally". The pack in question is included this way:
Results in
Both of these result in nothing. As said, I added this to the *.csproj as well, but no change at all:
Searching for the asset pack on via adb shell (with root access) does not yield any results. https://i.imgur.com/jLTEPz5.png When I build a release package, I can see that the AssetPack is included as expected: https://i.imgur.com/yHym4g5.png So either it's not working. Or at least not in debugging. Or the documentation is not complete. |
You should use a different syntax for Debug:
This assumes that the Debug build is using the APK package format (see Then for Release, you use:
This assumes that the Release build is using the AAB package format (see I don't know how |
There is no "banks" subdirectory in my app and I also do not see any .bank files at all in bin/ or obj/* from my VisualStudio output. Also why would I need to specify the MauiAssets as AndroidAsset and move them around while Maui should already do this and if this is really necessary, why is it not part of the documentation? As said, I can see the AssetPack in the *.abb output when I use the publish function of VisualStudio but it seems to not work when debugging so it's untestable? I haven't even converted 10% of my Xamarin.Forms app to Maui and it's already super frustrating due to documentation and things not working as expected. But this case is probably a Xamarin.Android thing and not even Maui's fault. So the question remains, why the InstallTime asset is missing. Or is it that, "InstallTime" is not even the proper tag and it needs to be "install-time" like it is on the Android documentation? |
It was just a short example, so please let me explain more. You are expected to replace the assets and their paths with your own assets and their paths. In our project, we have an asset called Master.bank (it's a sound bank file), located in The two asset paths work so that:
This allows us to debug things in the debug mode using APKs, while putting them into an asset pack in the release mode. Naturally, you can configure things how you like, but this is the setup we are using currently. |
From the Android docs (and ours)
'--local-testing' only works for OnDemand and FastFollow. For InstallTime you just don't use the This is probably because google can't really emulator how the installtime works for debug since those package are downloaded immediately while the app is downloading, and the app will not be reported as installed until the apk and the installtime packages are installed. The conditional suggested by @TommiGustafsson-HMP is a good way to handle <ItemGroup>
<MauiAsset Update="Resources\Raw\*" AssetPack="installtime" Condition=" '$(AndroidPackageFormat)' != 'apk'"/>
</ItemGroup> or you can key off the <ItemGroup>
<MauiAsset Update="Resources\Raw\*" AssetPack="installtime" Condition=" '$(Configuration)' != 'Debug'"/>
</ItemGroup> |
As the "Community Question" part this repo links to just ends in a 404 when posting a question and after multiple hours of trying to solve it and find the answer to this, I'm pretty certian it's just another bug with MAUI:
With Asset packs for Android now in MAUI .NET 9, I wonder how to use the iOS equivalent of On Demand Resources in MAUI. I thought I could port over a few of my older Apps (which still use Xamarin.Forms) to MAUI but those app are using On Demand Resources for iOS to download ressources only when needed. However, neither the Build Action BundleResource nor the On Demand Resource Tags can be set in a MAUI project. So how is it supposed to be set to work for iOS and Android?
There is not option on files at Platforms/iOS/Resources/* and also not on Resources/Raw/* where I can set the tags for iOS. In Xamarin.Forms, I had the option to set those tags for BundleResource files in my iOS project.
The text was updated successfully, but these errors were encountered: