Mendix PhoneGap Build app template
npm install mendix-hybrid-app-templateNode.js. This code was tested with version 6. You can check by running node -v.
Node.js: brew install node
sudo apt-get install node
.zip file containing JavaScript and resource files.
$ npm install # install dependencies
$ npm run package # create ARM PGB package in dist or
$ npm run package:x86 # create x86 PGB package in dist
`
Then, go to https://build.phonegap.com/apps/ and click the
+ new app button. When asked, upload the PhoneGap Build package from the dist folder.
Through the command line
To build on PhoneGap Build through the command line:
`
$ npm install # install dependencies
$ npm run package # prepare build directory for ARM or
$ npm run package:x86 # prepare build directory for x86
$ npm run phonegap:login # login into the PGB service
$ npm run phonegap:build:android # build on PGB, alternatively use phonegap:build:ios
`
Customize DTAP endpoint
To target a specific DTAP endpoint with your app you can specify it as a parameter to
npm run package or npm run package:x86, e.g:
`
$ npm run package -- --env.target=test # target the test endpoint for ARM architecture
`
Possible targets are development, test, acceptance, production (default) and sandbox. For
convencience you can shorten these to the first letter.
App signing
In case you want to deploy your app on a real device, you will likely need to sign your app.
Please refer to the appropriate Cordova documentation for details:
- iOS
- Android
Build and run locally
If this is the initial build, first do some preparation:
`
$ npm install # install dependencies
$ npm run package:x86 # prepare build directory for x86 or
$ npm run package # prepare build directory for ARM
$ npm run platform:android # setup for Android or
$ npm run platform:ios # setup for iOS
`
If you cloned the repository or want to change some settings, edit the file config/parameters.json
(create it if necessary). It should at least contain the following properties, with values
appropriate for your app:
`json
{
"identifier": "io.mxapps.myapp",
"name": "My App",
"url": "https://myapp.mxapps.io"
}
`
For information on further customization, refer to Customizing your app.
Now, build and run the app:
`
$ npm run package:x86 # prepare build directory for x86 or
$ npm run package # prepare build directory for ARM
$ npm run prepare:all # prepare phonegap platform files
$ npm run start:emulator # run on emulator, alternatively use start:device
`
Customizing your app
When you first download this project, it is mostly empty. All functionality and styling is by
default implemented as part of one this project's dependencies, called mendix-hybrid-app-base.
You can customize your hybrid app in several ways. All defaults from the base package can be
overridden and/or extended, including the build process itself.
Folder structure
The project structure consists of the following elements:
- src/: this is where you place all customizations for your app
- www/:
- images: any images that you'd like to use on e.g. the login screen
- styles: CSS files with styling for e.g. the login screen
- scripts: JavaScript files that customize the behavior of your app
- index.html.mustache: Mustache template file used to generate the index page
- resources/: icons and splash screens
- config.xml.mustache: template file that is used to generate the Phonegap configuration file
- config/: this is where external configuration files go; these files are optional, overriding the
defaults. Example files containing the defaults are put here upon npm install. Possible
configuration files are:
- environments.json: a description of all available deployment environments for your app,
including the app IDs and URLs
- parameters.json: settings that influence some aspects of the build process and the resulting
app, such as Android/iOS support, offline mode, and pin login
- resources.json: descriptions of all resources, such as icons and splash screens, including
their types and sizes
- texts.json: translations/customizations for the static texts in the hybrid shell part of
your app
- build/: (generated) contains all intermediate build files, such as the bundles javascript and
css. The contents of this folder are overwritten every time you run a build
- dist/: (generated) the final build packages will end up here
- webpack.config.js: starting point for the build process
Basic app settings
Several simple app settings, such as the app name and identifier, can be set in
config/parameters.json. If you've downloaded this project from the Mendix Portal, the file is
already there. Otherwise, you can look at the config/parameters.json.example file.
Styling
To customize the styling of the login screen (including the pin screen), add a .css file to
src/www/styles/. It will be automatically picked up by the build process.
Page structure
To change the structure and contents of the login screen (including the pin screen), you can adapt
src/www/index.html.mustache.
Translations / custom text
All static text in the hybrid app can be customized and/or translated. To do so, create a file
config/texts.json containing the original text as keys and the replacement text as values. You can
take a look at config/texts.json.example to see which texts are available for translation.
Icons & Splash screens
Icons and splash screens are configured in two separate places. The image files themselves should be
stored in src/resources/. The configuration of each icon and splash screen should be updated in
config/resources.json. You can take a look at config/resources.json.example for an example.
In case you have downloaded this package through the Mendix Portal, all configured icons and splash
screens have already been prepackaged and preconfigured.
Client behavior (advanced)
You can run custom code in two specific cases:
- on client configuration setup
- on Mendix client load
To implement custom behavior for these cases, edit src/www/scripts/entry.js.
Customizing the build process (advanced)
You can customize the build process by making changes to webpack.config.js in the root folder of
this project. All Webpack configuration you add here will be merged with the default Webpack
configuration. You can read more about this in the
webpack-merge documentation.
Upgrading the base package
Default functionality and styling is implemented in the mendix-hybrid-app-base package. We will
occasionally release updates to this package. You can upgrade the base package by running
npm upgrade from the root of your project.
Troubleshooting
PIN feature on iOS simulator
When using the PIN feature while running your app on an iOS simulator, you experience an issue where the
app will prompt you to setup a PIN every time app is launched. This is due to the underlying way Cordova access the Keychain.
Either use a device, or enable Keychain Sharing in Capabilities` of your project.