Walkthrough - Ionic Framework, Barcode Scanner, Android, iOS
Goal
- Build BarCode Scanner application on iOS and Android platforms.
- Use cordova and ionic framework.
- Use windows 8 64bit for Android development.
- Use OSX for iOS development.
- Keep the source code on bitbucket.org as Git. It must be sharable between windows and OSX.
Before Starting…
- Cordova is engine. Phonegap is Adobe’s productized package that wraps Cordova.
- Ionic Framework is comparable to Phonegap. It is built upon Cordova. It lays AngularJS framework for www content and use Angular directive to support ionic-specific directives.
- www folder content is generic across platform.
- When you install platform it contains path information which is OS-specific. (unix style vs DOS style) So you need to decide which OS to use per each platform.
Step 1: Install Android environment on Windows
- Install JDK 7 or later. http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
- Install Android SDK. Let’s say we did on C:\Programs\Android\android-sdk. http://developer.android.com/sdk/index.html?hl=sk
- Execute
C:\Programs\Android\android-sdk\AVD Manager.exe
and create one Android Virtual Device. - Make sure Environment Variables are set properly.
System Variables:
- ANDROID_HOME: C:\Programs\Android\android-sdk\tools
- JAVA_HOME: C:\Program Files\Java\jdk1.7.0_40 (or wherever you installed)
- PATH should include: C:\Programs\Android\android-sdk\platform-tools;C:\Programs\Android\android-sdk\tools;
Step 2: Install Cordova and Ionic Framework on Windows
- Install nodejs for npm. http://nodejs.org/
- Install ant.
- I unzipped http://www.apache.org/dist/ant/binaries/apache-ant-1.9.4-bin.zip under C:\Programs\apache-ant-1.9.4.
- And then added C:\Programs\apache-ant-1.9.4\bin; to PATH.
- Launch Command Prompt and run this. http://ionicframework.com/docs/guide/installation.html
- Build initial app
- Cordova command line interface: http://cordova.apache.org/docs/en/3.4.0/guide_cli_index.md.html#The%20Command-Line%20Interface
You should see Ionic Blank Starter screen on Android Virtual Device window.
Step 3: Test MyApp on Android device
- Connect Android device to Windows 8 computer on USB port.
- On Android device, enable USB Debugging.
- On Windows 8 computer, run the following.
You should see Ionic Blank Starter on your Android device.
Step 4: Add Barcode Scanner plugin for android platform
- Install BarcodeScanner on android platform.
- Modify index.html.
- Add js/MainController.js
- Test
You should see Scan button on your Android device.
Step 5: Debugging Android Device from Windows
- Install weinre (WEb INspector REmote).
- Add INTERNET permission on MyApp\platforms\android\AndroidManifest.xml.
- Launch weinre server.
- Put local IP address using –boundHost.
- If 8080 is occupied, you can change it with –httpPort. * Parameters are case sensitive. If you put incorrect case, it won’t raise error but just ignore the setting.
- Add one line on index.html.
- Open browser window for http://192.168.0.114:8081/client/.
- Launch the app on Android device. The browser window is linked to the Android device.
Step 6: Commit MyApp to BitBucket.org from Windows
- Install git. http://git-scm.com/downloads
- Got to BitBucket.org and create a git repo called MyApp.
- Run the following.
Step 7: Run it from OSX
- Install git.
- Install nodejs.
- Install cordova, ionic, ios-deploy (launch the app on iOS device), ios-sim (launch the app on iOS simulator), and plugman.
- Get the code from BitBucket.
-
Open XCode, connect iOS device to OSX machine, and select “Use for development” using XCode Organizer. https://developer.apple.com/library/ios/recipes/xcode_help-devices_organizer/articles/provision_device_for_development-generic.html
-
Add ios platform, and run from iOS device.
- Debugging works fine with weinre, but you can also use Safari’s Web Inspector. http://phonegap-tips.com/articles/debugging-ios-phonegap-apps-with-safaris-web-inspector.html
Written on May 12, 2014