Packaging, deploying, and distributing apps / Packaging for a mobile device |
Packaging prepares and packages all files required to deploy an app onto a mobile device.
In other words, packaging involves identifying what files are needed for the app, organizing those files, and creating a package file that can be deployed to the app. The specifics are summarized in the following paragraphs.
To package your app, start by having an inventory of all files needed to run the app on the mobile device. Some of these files will be in your source directory structure (such as image files), while others will sit in your target directory structure (the compiled binary files).
You must also define the directory structure you will need to create in the Root directory for your mobile device. This may sound complicated, but in reality it is quite simple. For both the Android and iOS devices, you can place all of the files required into a single folder. If you examine the default packaging nodes provided when you create a new BAM Mobile Project (.4pw), you see that all files end up in the directory $(ProjectDir)/bin, which is the packaging Root directory. You could build a more complex Root directory structure, however it is not necessary.Once you have your inventory of required files and your plan for the directory structure on your device, you can build your packaging node.
In the Package node, you define the Root directory and specify which platform the package is for.
The Source directory indicates where the files exist prior to packaging, the Destination directory indicates where the files will be located in the package. The Destination directory must be located within the Root directory. In the Directory node, the Included files and Excluded files properties tell which files from the Source directory to include or exclude, based on filtering criteria (such as the filename or file extension).
If you create a flat file to hold all the files required by the app, a flat file is created on the mobile device. This is what is done by the default packaging nodes when you create a new BAM Mobile Project (.4pw).
For your iOS applications, however, the directory created and holding the app files is a read-only directory. If there exists writable files that need to be updated by the app (such as a database file), those files must be placed into a read-write directory on the device. Moving files from the read-only directory to a read-write directory is not something handled by packaging. You must handle it within your app.
At deployment, when your application initially starts, we recommend that you copy the writable files from the application directory (using the function base.Application.getProgramDir()) to the current working directory (using the function os.Path.pwd()).
For an example, open the OfficeStoreMobile demo project, open the OrdersApp.4gl intermediate file, and look for the OrdersApp_install function. In this function, the os.Path.copy method is used to copy a database file from the read-only source directory to the read-write destination directory.
In addition to simply copying writable files, one of the first things your app needs to do is create the user database. This database may use the initial database file when creating the user database, or it may create one with a different schema for the user.
For an example, open the OfficeStoreMobile demo project, open the OrdersApp.4gl intermediate file, and look for the OrdersApp_install function. In this function, the os.Path.copy method is used to copy a database file from the read-only source directory to the read-write destination directory.
The example provided by the OrdersApp.4gl example needs to be evaluated in terms of initial installation and in terms of future upgrades to the application. This example solves how to initially place the file in the read-write directory. It does NOT cover an upgrade strategy. The developer needs to ensure that any new files need to be written to the read-write directory are written, that files that should not be overwritten are not overwritten, and that files that need to be updated or merged or replaced are handled. See Manage App updates.