Adding Common Dependencies
Generated Astro projects come with an existing /app-www
folder which consists of packaged www content. The folder is already configured to allow the Android and iOS platform to reference its files, but you may wish to include other common dependencies to your project.
To allow referencing of common dependencies in your Android and iOS app, you will need to place the dependencies in a folder that is external to the /android
and /ios
directory.
For example:
+-- project/
| +-- android
| +-- ios
| +-- common-dependencies/
| | +-- dependency1
| | +-- dependency2
Then make the necessary configurations for each platform detailed below.
Android
Add a symlink in the app assets folder which links to the directory you wish to reference. This can be achieved with the following command:
ln -s common-dependencies android/app/src/main/assets/common-dependencies
iOS
With your app.xcworkspace
open, complete the following steps to add common-dependencies
to your Build Phases:
- Select the app project target in the navigation panel located on the left of the Xcode IDE.
- Select Build Phases > Copy Bundle Resources at the top of the project editor.
- Click the Add button (+) to add
common-dependencies
to the list of bundle resources. - Ensure that "Copy items if needed" is unselected otherwise the bundle resource will not be updated if changes are made.
- Select "Create folder references" to maintain the directory structure in your
common-dependencies
folder.
Alternatively, you can drag the folder containing common dependencies into the navigation panel and proceed to step 4.
Note: If you have a symlinked file within your common-dependencies
folder you will need to complete some additional steps to resolve symbolic links when copying bundle resources:
- Click the Add button (+) at the top of the project editor to add a Copy Files Phase.
- Set
Destination
toResources
. - Set
Subpath
to the path of the folder which contains the symlink incommon-dependencies
. - Check "Copy only when installing" if you wish to copy the resources only when you are installing the app.
- Ensure that "Copy items if needed" is unselected otherwise the bundle resource will not be updated if changes are made.
- Select "Create folder references" to maintain the directory structure.
Accessing Newly Added Dependencies
The files in the common-dependencies
folder can be accessed from app.js
using the file scheme:
file:///common-dependencies/filename.extension