Now that Xamarin supports creating App Bundles in the .aab format, is there any way to use Visual Studio to add downloadable Asset Packs to the bundles?
-
Xamarin already binds the Play Core library: https://github.com/xamarin/XamarinComponents/tree/master/Android/Google.Play.Core – SushiHangover Sep 14 '20 at 20:46
-
Yes but how do you actually create the asset packs and add them to the bundle in visual studio? – Shimfish Sep 15 '20 at 06:48
-
Visual Studio does not have any built-in UI-based features to create asset packs, but just like creating `.obb` files, you can do it via the Android build tools or via Android Studio. – SushiHangover Sep 15 '20 at 13:54
-
How do you do that if you've created the .aab in Xamarin? Can you use the tools to add to an existing .aab? – Shimfish Sep 15 '20 at 14:10
-
In short, yes, `.abb` are just signed zip files (its file structure is well documented by Google) . Before Xamarin supported building `.abb` directly, you could create one via the `.apk` build artifacts (i create a script file for a client to do it). It really depends upon your needs, asset packs are really oriented to game development (as `.obb` are). Unity, Unreal, & Android Studio are the only UIs that I currently know of that directly support them via a UI feature set, will Xamarin ever support them(?), who knows..., they do not support `.obb` due to the very small user base overlap. – SushiHangover Sep 15 '20 at 14:48
-
So I just add an asset_pack folder to the .aab zip? What goes in the asset pack manifest.xml? Do I have to add anything to the main manifest? – Shimfish Sep 15 '20 at 16:12
2 Answers
Here's a guide for creating install-time asset packs on Windows 11 manually using Windows Subsystem for Linux:
Install Windows Subsystem for Linux (WSL)
Download aapt2 (Linux version) from Google Maven (download the jar file and then extract its contents with "jar xf"), e.g. https://dl.google.com/android/maven2/com/android/tools/build/aapt2/7.2.0-alpha06-7909850/aapt2-7.2.0-alpha06-7909850-linux.jar or get it right here: https://drive.google.com/file/d/1sb9KevVgRA9PTAGqc74rWorWBtXWYnWq/view?usp=sharing (You can download Java from https://www.java.com/en/download/ to get the jar utility.)
Create an appropriate AndroidManifest.xml (example here: https://drive.google.com/file/d/1sb0BeyWcs7edz_qL9aTqkt55pGmhhJ4e/view?usp=sharing); Change the package attribute to match your app id, such as com.company.yourgame. Make sure to that the file uses Linux line endings (it might work with Windows line endings, too).
Create a directory for the asset pack (let's say C:\assetpack) on Windows.
Put aapt2 and AndroidManifest.xml to that directory.
Create Assets directory under the assetpack directory. Put all assets there.
Download this bash script file: https://drive.google.com/file/d/1saOfj5a3wHIrB5nTJsDqv0GhMnaP3m_n/view?usp=sharing and put it into the assetpack directory. Make sure that it has Linux line endings. It will not work with Windows line endings.
Start WSL and navigate to the assetpack directory by "cd /mnt/c/assetpack"
Run "./createassetpack.sh assets.zip com.company.yourgame", where com.company.yourgame is the id of your app. assets.zip is the name of the final zip file.
assets.zip will now appear in the assetpack directory. Copy this file to your solution, let's say to assetpack\assets.zip under your Xamarin.Android project.
Go to your Xamarin.Android project and edit its project file with a text editor. Add the following code after all ItemGroups in XML:
<ItemGroup> <AndroidAppBundleModules Include="assetpack\assets.zip" /> </ItemGroup>
Now, you can access your assets through AssetManager. For example, in your MainActivity.cs, you can write:
using(var stream = Assets.Open("myasset.png")) { //Code goes here }

- 98
- 1
- 9
They are working on it:
https://developercommunity.visualstudio.com/t/xamarinandroid-asset-delivery/1527043
https://github.com/xamarin/xamarin-android/issues/4810#issuecomment-902235355
So, we need to wait a bit more.

- 98
- 1
- 9
-
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/30250136) – eglease Nov 04 '21 at 01:38