In some cases, you will need to import your assets to Xcode so native code can read it.
You will have to follow these steps:
- In Xcode, open the
ios/Runner.xcworkspace
of your Flutter project and navigate to the Runner folder. - Drag and drop the asset file into the Runner folder. This will copy the asset file into the main bundle and create a reference to it in your project's project.pbxproj file.
- If asked, make sure you select the options "Copy items if needed" and "Create groups". In "Add to targets", select your app Runner.
Here are two screenshots of the steps to help you:
That's right, you have one version of your asset probably in your assets
folder, and now another one in your ios/Runner
folder.
That's not really a good thing since this could add significant weight to your app. Keep reading to see the solution.
The workaround I found uses symbolic links. A symbolic link creates a file in your directory and acts as a shortcut to a file or folder. This way, there is only one asset stored in the project, and the other become just a light-weight link.
First, you can delete your asset in the ios/Runner
folder with this command. This will keep the reference to the file though.
rm ios/Runner/my_asset.mp3
Then, create the symbolic link like this:
ln -s assets/audio/my_asset.mp3 ios/Runner/my_asset.mp3
That's it !
If you run the command ls -l
in you Runner folder, you will see that the symbolic link is around 36 bytes only:
Greate