How to Make an iOS Asset Bundle

How to make an iOS asset bundle?

Answer is stupidly simple

Make a folder in finder, add files to it, rename it to bundlename.bundle

drag into Xcode - success!

to access, use the form of PathToMainBundle+"/bundlename.bundle"

How do you create a .bundle to store images?

There's some good advice regarding creating and accessing an asset bundle in the answers to this question.

How to create my own bundle in Xcode, for iPhone application

First of all, since your question is tagged iPhone, you can only include code in your bundles on the iPhone. So basically you can only use bundles to package up pictures and sound files and other static data.

When you create a new project in XCode, there is an option to make the target a bundle (under Framework & Library), but an assets bundle is just a directory with a .bundle suffix. I generate mine with this little script:

#!/bin/bash
echo "Building assets bundle."
if [ -d ./MyAssets.bundle ]; then
rm ./MyAssets.bundle/*
else
mkdir ./MyAssets.bundle
fi
find ./assets -type f -print0 | xargs -0 -J% cp % ./MyAssets.bundle

(I'm no bash hacker, so this can probably be improved in countless ways. Suggestions welcome!)

This takes a folder hierarchy and flattens it (I detest hierarchies) into a single directory which is named MyAssets.bundle. I trigger this script from a separate build phase when in projects that import the bundle, so that changes are automatically tracked.

If you want to learn how to create framework bundles, it's a bit more complicated (you have to follow certain conventions and include info in plists), but for iPhone bundles, this is pretty much all you will need to know and do.

How to download an assetbundle into the app folder for IOS/Android and get the required model from it?

Use the new Addressables feature. It will handle downloading to the appropriate place automatically.

Loading images from assets folder from a bundle

Two things to check.

1) make sure your assets bundle has an Info.plist with a bundle identifier set in it. From your screenshot it doesn't look like this is the case.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>MyBundle</string>
</dict>
</plist>

2) Make sure your bundle has a compiled assets catalog in it. Should be named Assets.car. I don't think Xcode will just compile an Assets.xcassets folder inside a resource bundle (the bundle is effectively opaque to Xcode; likewise it wouldn't compile any .m source files you put in there). You may need a custom build step to copy the compiled Assets.car file into your assets bundle before the assets bundle is copied into the app bundle.

You can check these by finding your app bundle and right clicking on it then "Show Package Contents", then again on the contained bundle.

Manual assets compilation command:

xcrun actool Images.xcassets --compile . --platform iphoneos --minimum-deployment-target 9.0

Assetbundles not working with iOS

This means that your target device was not iOS when you built the Asset bundle. Change your target to iOS then rebuild the Asset Bundle.

Recompile and re-upload to iOS and that should solve your problem.

If that didnt work then...
If you built your AssetBundle while the scripting backend was set to IL2CPP, but then you use them with the .NET scripting backend, that error would occur too. Solution is to rebuild your Asset Bundle after changing to .NET scripting backend through the player settings.

Also try replacing BuildTarget.iPhone with EditorUserBuildSettings.activeBuildTarget so that that Bundle would automatically build for any build target currently selected.

Building Unity game for iOS platform with Asset Bundle

Unity includes all scenes that are listed in the "Build" window and all assets referenced in this scenes in the build.

If you want to exclude some assets and load them from the asset bundle instead, remove the scenes from the "Build" window and load them from the asset bundle instead.



Related Topics



Leave a reply



Submit