Development Environment
You only need to follow these instructions if you wish to modify the mobile apps. I've provided the source code that you can modify and improve as you wish, and then deploy it to your own phone or tablet without needing a paid developer account to the mobile app stores.
To be able to build and deploy the app, you need to have the appropriate development environment setup. This page outlines how to setup this environment from scratch, assuming that none of the requirements have been previously installed.
Where possible I accept the default values. This may result in options that we don't need being installed, but I prefer to have a "standard" environment setup where possible.
To setup the environment to modify the sketch, please see the Arduino section of the install page.
The following instructions were tested on Mac OS X 10.11 El CapitanWindows 10.
Ionic Platform
The app is created using version 1 of the Ionic Framework. Ionic allows for the creation of "hybrid" applications that can be run on multiple platforms from a single code base of HTML 5, CSS and Javascript. Ionic leverages Cordova to support this code reuse across platforms, and the NodeJS javascript runtime environment.
To install Ionic, I followed the steps as outlined on the Ionic Getting Started page (and added a step for xml2js
). I've listed the steps out below, but if you run into problems, follow the advice of that page.
Instal Node.js
At the time of writing, Node.js v4.x.x is supported by Ionic, whereas the newer v5.x.x is not. As such we will install the version 4 LTS (Long Term Support) edition of Node.js.
Visit the NodeJS homepage, and download the latest version 4 LTS edition that is appropriate for your platform. For this example it was v4.2.6 LTS
- Run the installer that was downloaded
- Click "Continue" on the "Introduction" screen
- Click "Continue" on the "License" screen
- Click "Agree" to accept the license agreement
- The standard install is ok, so just click "Install" on the "Installation Type" screen
- Enter the "Username" and "Password" of an administrator on the computer, and then click "Install Software"
- Click "Close" at the "Summary" screen
- Run the installer that was downloaded
- Click "Next" on the setup wizard welcome page
- Click "I accept the terms in the License Agreement" checkbox
- Click "Next"
- Accept the default install location and click "Next"
- Accept the defaults in the "Custom Setup", and click "Next"
- Click "Install"
- Click "Yes" to allow this the "User Account Control" "Do you want to allow this app to install software on your PC?" dialog
- Click "Finish"
Node.js should now be installed.
Instal Cordova
To install Cordova, we use npm
via the command line. npm
was installed as part of the Node.js installation.
Information on Cordova can be found on it's website.
- Start "Terminal" from "Applications" "Utilities"
- Run
sudo npm install -g cordova
- Enter your administrator password when prompted
- Start "Command Prompt" hitting "Windows" + "R" keys, then typing
cmd
- Run
npm install -g cordova
Cordova should now be installed.
Install Ionic
To install Ionic, we use npm
via the command line. npm
was installed as part of the Node.js installation.
Information on Cordova can be found on it's website.
- Start "Terminal" from "Applications" "Utilities"
- Run
sudo npm install -g ionic
- Enter your administrator password when prompted
- Run
ionic
- You will be prompted to say that "xcodebuild" command requires the command line developer tools. Click "Install" to install these tools
- Click "Agree" to the license agreement
- Start "Command Prompt" hitting "Windows" + "R" keys, then typing
cmd
- Run
npm install -g ionic
Ionic should now be installed.
Install XML2JS
To install xml2js, we use npm
via the command line. npm
was installed as part of the Node.js installation.
xml2js is used to allow a build script within the BlueCube project to modify the config.xml file.
- Start "Terminal" from "Applications" "Utilities"
- Run
sudo npm install -g xml2js
- Enter your administrator password when prompted
- Start "Command Prompt" hitting "Windows" + "R" keys, then typing
cmd
- Run
npm install -g xml2js
xml2js should now be installed.
iOS Support
iOS support requires a Mac. While there are some workaround, I only provide instructions for use with a Mac.
To be able to build and deploy iOS applications, you need to install additional components. If you don't plan on building the iOS version of BlueCube, you can skip this section. I've installed the items mentioned on the Cordova iOS Platform Guide. If you encounter any problems please refer to this link.
Install Xcode
Xcode is Apple's Integrated Development Environment (IDE) for iOS Development.
- Visit the XCode page within the Mac App Store
- Click on "Get"
- Click on "Install App"
- If prompted, enter your AppleID and password, then click "Sign In"
- If two factor authentication is on, select the device to verify your identity and click "Continue"
- Enter the verification code
Xcode will now download into your "Applications" folder. Please note that depending on your connection speed this may take a little while.
- Once Downloaded, launch Xcode via "Applications" "Xcode"
- Agree to the "Xcode and iOS SDK License Agreement"
- Enter your administrator "Username" and "Password" then click "OK"
Xcode is now installed
Install iOS-Sim
iOS-Sim allows you to work with the iOS Emulator from the Cordova / Ionic command line tools.
- Start "Terminal" from "Applications" "Utilities"
- Run
sudo npm install -g ios-sim
- Enter your administrator password when prompted
iOS-Sim is now installed
Install iOS-Deploy
iOS-Deploy allows you to work with the iOS devices from the Cordova / Ionic command line tools.
- Start "Terminal" from "Applications" "Utilities"
- Run
sudo npm install -g ios-deploy --unsafe-perm=true --allow-root
- Enter your administrator password when prompted
iOS-Deploy is now installed
Android Support
To be able to build and deploy Android applications, you need to install additional components. If you don't plan on building the Android version of BlueCube, you can skip this section. I've installed the items mentioned on the Cordova Android Platform Guide. If you encounter any problems please refer to this link.
Java Development Kit
Android applications are written in the Java programming language, and as such require the Java Development Kit (JDK) installed (please note that this is different then the typically installed Java Runtime Environment (JRE)).
- Visit the Java Development Kit website
- Accept the license agreement
- Download the Mac OS X x64 installer
- Run the downloaded installer
- Click "Continue" on the "Introduction" screen
- Click "Install" on the "Installation Type" screen
- Enter the "Username" and "Password" of an administrator on the computer, and then click "Install Software"
- Click "Close" on the "Summary" screen
- Visit the Java Development Kit website
- Accept the licence agreement
- Download the appropriate installer (Windows x86 or Windows x64)
- Run the downloaded installer
- Click "Yes" to allow this the "User Account Control" "Do you want to allow this app to install software on your PC?" dialog
- Click "Next" to start the install wizard
- The default install options are fine, so click "Next"
- The default install location is fine, so click "Next"
- Click "Close"
The Java Development Kit is now installed, however we need to add an environment variable to it's location. To do that:-
- Click on the "Start" menu
- Type "Environment"
- Click on "Edit the system environment variables"
- Click on "Environment Variables..." on the "Advanced" tab of the "System Properties" window that opened
- Click "New..."
- Variable Name: JAVA_HOME
- Variable Value: C:\Program Files\Java\jdk1.7.079
- It's best to click "Browse Directory..." and find where the JDK was installed, as the location maybe different then the one I have specified
- Click "OK" to set the new variable
- Click "OK" to close the "Environment Variables"
- Click "OK" to close "System Properties"
Android Studio
Android Studio is Google's Integrated Development Environment (IDE) for Android development.
- Download Android Studio from here
- Accept Licence Agreement and Download
- Open the downloaded disk image
- Drag Android Studio into the "Applications" folder
- Run "Android Studio" from the "Applications" folder
- When prompted, click "Open" to allow Android Studio to run as it was downloaded from the internet
- On the "Complete Installation" screen, select "I do not have a previous version of Studio or I do not want to import my settings"
- Click "Next" on the welcome screen
- Ensure "Standard" is selected on the "Install Type" screen and click "Next"
- Verify the selected settings and click "Finish", taking note of the "Destination Folder"
The installer will now download additional items that are required. This may take a while.
- Click "Finish" when the install is complete. If the "HAXM" installation fails, don't worry about it. "HAXM" is used for speeding up the emulator, but we don't use the emulator for this app
Android Studio is now running
- Quit Android Studio
We need to add the location of the Android tools to the PATH
environment variable so that Cordova / Ionic can use them. To do this:-
- Start "Terminal" from "Applications" "Utilities"
- Run
pico -w ~/.bash_profile
- Add
export PATH=${PATH}:/Users/<user>/Library/Android/sdk/platform-tools:/Users/<user>/Library/Android/sdk/tools
to the file- If you didn't change the install path, then the above will just need you to replace
<user>
with your short user name (the value before the $ sign in terminal). If you changed the install location, use the location that was specified in "Destination Folder" during step 10, replacing the text uptoplatform-tools
andtools
- If you didn't change the install path, then the above will just need you to replace
- Hit
Ctrl+O
then enter key to save the file - Hit
Ctrl+X
to exit - Run
source ~/.bash_profile
- Download Android Studio from here
- Accept Licence Agreement and Download
- Run the downloaded installer
- Click "Yes" to allow this the "User Account Control" "Do you want to allow this app to install software on your PC?" dialog
- Click "Next" on the "Welcome" screen
- The default components are fine, so click "Next"
- Click "I Agree" to the licence agreement
- The default install locations are ok, so click "Next" (take note of the Android SDK Installation Location)
- The default emulator setup settings are ok, so click "Next"
- The default start menu folder is ok, so click "Install", and wait for it to finish
- Click "Next" once the installation is complete
- ----Uptick "Start Android Studio" and then click "Finish"
- XXXStart the app, and don't import
- XXXAllow access for Android Studio if asked by the windows firewall
We need to add the location of the Android tools to the PATH
environment variable so that Cordova / Ionic can use them. To do this:-
- Click on the "Start" menu
- Type "Path"
- Click on "Edit the system environment variables"
- Click on "Environment Variables..." on the "Advanced" tab of the "System Properties" window that opened
- Click "New..."
- Variable Name: ANDROID_HOME
- Variable Value: C:\Android\sdk
- It's best to click "Browse Directory..." and find where the Android SDK was installed. using the location that was specified in "Android SDK Installation Location" during step 8
;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools
to the end of what is already thereAndroid SDK
The Android SDK contains the required components to develop Android applications against particular API's (Android versions).
- Start "Terminal" from "Applications" "Utilities"
- Run
android
- When the "Android SDK Manager" loads, it will check for any updates, and most likely find some. This is ok. We will install these updates in addition to the items we require
- Expand "Android 5.1.1 (API 22)"
- Click the check box next to "SDK Platform" under "Android 5.1.1 (API 22)"
- Click "Install # Packages" to install that package and any updates that are available
- Select a package on the left, then click "Accept License" on the right &
- Click "Install"
- Start "Command Prompt" hitting "Windows" + "R" keys, then typing
cmd
- Run
android
- When the "Android SDK Manager" loads, it will check for any updates, and most likely find some. This is ok. We will install these updates in addition to the items we require
- Expand "Android 5.1.1 (API 22)"
- Click the check box next to "SDK Platform" under "Android 5.1.1 (API 22)"
- Click "Install # Packages" to install any updates that are available
- Select a package on the left, then click "Accept License" on the right
- Click "Install"
Build & Deploy
Change Project ID
The project has a given ID of "ninja.secretcode.BlueCube". This ID needs to be unique for each developer that builds the apps. This change needs to be completed every time you download a new version of BlueCube (you can reuse the ID you choose for each subsequent version). To edit it:-
- Browse to "BlueCube" "IonicApp"
- Edit
config.xml
in the text editor of your choise - On the second line where it says
id=ninja.secretcode.BlueCube
change it so that it is unique to you. Normally the name ID is in reverse DNS format, so if you own "fredsautos.com", the ID would beid=com.fredsautos.BlueCube
. Otherwise just add a random number to the end of "BlueCube", without any spaces or punctuation. If in doubt, add the machines MAC address at the end. On OS X runifconfig en0 ether | grep ether | awk '{ print $2 }' | sed s/\://g
- Save the file and quit the text editor
- Start Terminal "Applications" "Utilities" "Terminal"
- Change to the BlueCube folder by
cd
and dragging the "IonicApp" ("BlueCube" "IonicApp") folder onto the terminal window, then hitting "Enter". For example, I have the BlueCube folder on my desktop, and my username isadam
. In this case the command wascd /Users/adam/Desktop/BlueCube/IonicApp
- Remove the previously configured platforms
ionic platform rm ios
ionic platform rm android
- Re-add the iOS platform if you wish to build the iOS app
ionic platform add ios@3.9
- Re-add the Android platform if you wish to build the Android app
ionic platform add android@4.1
- Browse to "BlueCube" "IonicApp"
- Edit
config.xml
in the text editor of your choise - On the second line where it says
id=com.example.BlueCube
change it so that it is unique to you. Normally the name ID is in reverse DNS format, so if you own "fredsautos.com", the ID would beid=com.fredsautos.BlueCube
. Otherwise just add a random number to the end of "BlueCube", without any spaces or punctuation. If in doubt, add the machines MAC address at the end. Rungetmac
, from the command prompt and pick the "Physical Address", removing the hyphens - Save the file and quit the text editor
- Start Command Prompt "Windows Key + R" and run "cmd.exe"
- Change to the BlueCube folder by
cd
and dragging the "IonicApp" ("BlueCube" "IonicApp") folder onto the command prompt, then hitting "Enter". For example, I have the BlueCube folder on my desktop, and my username isadam
. In this case the command wascd "C:\Users\adam\Desktop\BlueCube\IonicApp"
- Remove the previously configured platforms
ionic platform rm ios
ionic platform rm android
- Re-add the Android platform
ionic platform add android@4.1
Build
Every time you modify the BlueCube's code, you need to instruct ionic to build it. This prepares all of the items in a platform specific way. You build the code from the command line.
- Start "Terminal" from "Applications" "Utilities"
- Change to the to "BlueCube" "IonicApp" folder by running
cd /path/to/BlueCube/IonicApp
(you can drag the IonicApp folder from Finder into the Terminal window to automatically provide the complete path) ionic build
(to build both iOS and Android apps), orionic build ios
(if building iOS app), orionic build android
(if building Android app)
- Start "Command Prompt" hitting "Windows" + "R" keys, then typing
cmd
- Change to the to "BlueCube" "IonicApp" folder by running
cd "C:\Users\Adam\BlueCube\IonicApp"
(you can drag the IonicApp folder from Explorer into the command window to automatically provide the complete path) ionic build
- You may be asked by the windows firewall to allow access for Java. It is up to you if you wish to allow this access.
Deploy to Mobile Device
Ensure that before deploying to a mobile device, that the latest version of the code has been build, as outlined in the instructions above.
iOS
- Connect your iOS mobile device to your Mac with a lightning cable, and unlock the device
- If requested, Trust the computer on your mobile device (this should only occur the first time you connect the mobile device)
- Open the Xcode project by browsing to "BlueCube" "IonicApp" "platforms" "ios" and double clicking on "BlueCube.xcodeproj"
- Xcode will launch, and the project will load (which can take a while the first time - progress is shown in the toolbar at the top of the Xcode window)
- Ensure that in the top toolbar, that BlueCube and your mobile device are selected. If not, click on this and pick your phone from the list of available options
- Click Build (the black arrow icon). The first time you do this you may need to do the following tasks:-
- If prompted, enable "Developer Mode" and provide your password when requested
- You may get an error saying 'Failed to code sign "BlueCube"', and are provided an option to "Fix issue". If this occurs, click the "Fix issue" button
- When asked, click "Add" to add your Apple ID
- Enter your Apple ID and Password, then click "Sign In"
- If two factor authentication is enabled, select the phone to send the code to, and click "Continue", then enter the provided code and click "Verify"
- You will now see the Accounts tab of the preferences window, and your AppleID will be listed. Close this window.
- If you have multiple teams associated with your AppleID, select the one you want to use and click "Choose"
- If you have your AppleID developer account setup on a different mac for use with Xcode, you will need to export the developer profile (via Preferences -> Accounts -> Cog icon), then click Import Developer Profile, otherwise let Xcode download the signing certificates that are required
- Finally Always Allow codesign to sign the code
- After the code is uploaded to your mobile device, Xcode may give you a 'Could not launch "BlueCube"' error, mentioned that the process launched failed because of security. It this happens, on your mobile device:-
- Launch "Settings"
- Select "General"
- Select "Device Management"
- Select the option that represents your Apple ID
- Tap "Trust 'Apple ID'"
- Tap "Trust"
- Rebuild the app in Xcode
- Test the app on your mobile device
- Stop the app via the stop icon on the top toolbar in Xcode
At this stage you can quit the Xcode, and use the app like a normal app.
Android
To be able to deploy the app to your Android device, we need to enable USB Debugging. To do that:-
- Launch the "Settings" application on your Android device
- Select "About phone" or "About tablet" from the bottom of the list of settings
- Scroll to the bottom of the information, and find "Build number"
- Tap "Build number" seven times
- "You are now a developer" will be shown when this has been successful
- Tap the back button to return to the settings menu
- Select "Developer Options" menu which has now been added to the settings menu
- Enable "USB debugging"
Your mobile device is now ready to have the app deployed to. To deploy the app:-
- Connect your mobile device to the computer via USB, and unlock it
- If prompted, select "Always allow from this computer" and touch "OK" on your device
- Launch Android Studio
- Select "Import project (Eclipse ADT, Gradle, etc.)"
- Select "BlueCube" "IonicApp" "platforms" "android" folder
- Click "OK", and wait for the app to load (which can take a while the first time - you can see progress in the bottom status bar after the initial stage has completed)
- Click Build (Green arrow in middle of top toolbar)
- Select "Choose a running device", and select your mobile device
- Click "OK"
- The application will launch, and you can see logs within Android Studio. Test the app as appropriate
At this stage you can quit Android Studio, and use the app like a normal app.
Other Tools
In addition to the above requirements, I find that there are some optional tools that make development easier. These tools are listed below:-
- TextWrangler is a free text editor from Bare Bones Software
- Git is a free version control system tool. I've used Git during the development of BlueCube
- SourceTree is a free graphical front end to Git from Atlassian
- Notepad++ is a free text editor
- Git is a free version control system tool. I've used Git during the development of BlueCube
- SourceTree is a free graphical front end to Git from Atlassian