For developers who are not familiar with Cordova, it is an open source solution that provides tools and templates that wrap web code and assets, allowing you to publish your web code and assets as if they were native apps. Cordova is also customizable via its plugin architecture which allows developers to extend the framework in order to access OS level APIs like the built-in contact list, as well as physical hardware on the device itself like the camera. Cordova also makes it possible for two way communication from the web app wrapper to the device’s native language.
To ensure that all core Cordova plugins will be natively supported, Amazon worked with the Apache community when adding Cordova support for the Amazon Fire OS platform. Here is how to set it up on your local computer, enable Amazon Web View and create a project from scratch.
1. Install Tools
You need to make sure you have all the required tools and libraries needed to compile and package an Android application. Download and install the following (please note these links will take you to third-party sites):
You'll need to have Java installed, and the Android SDK from developer.android.com/sdk. You may be presented with a choice of where to install the SDK, otherwise move the downloaded adt-bundle tree to wherever you store development tools.
For Cordova command-line tools to work, you need to include the Android [?] SDK's tools and platform-tools directories in your PATH environment.
To modify the PATH environment on Mac, Linux, etc.:
- Use a text editor to create or modify the ~/.bash_profile file, adding a line such as the following, depending on where the SDK installs:
This exposes SDK Tools in newly opened terminal windows. Otherwise run this to make them available in the current session:
$ source ~/.bash_profile
To modify the PATH environment on Windows 7:
- Click on the Start menu in the lower-left corner of the desktop, right-click on Computer, then click Properties.
- Click Advanced System Settings in the column on the left.
- In the resulting dialog box, press Environment Variables.
- Select the PATH variable and press Edit.
- Append the following to the PATH based on where you installed the SDK, for example:
- Save the value and close both dialog boxes.
You may also need to enable Java, Ant and/or Node from the command line. Open a command prompt and type "java", then "ant" then "node". Reinstall, or append to the PATH whichever fail to run:
2. Install Cordova
Make sure you are able to invoke npm (Node Package Manager) on your command line; it's added as a part of Node.js. (You can install Node.js from the nodejs.org homepage and type NPM in the command line to validate the installation.)
To install Cordova, open a command prompt/terminal and use:
$ npm install -g cordova
On Unix-like systems, you may need to append "sudo" to ensure it is installed correctly. See Cordova's documentation for the Command-Line Interface for more details.
3. Install the Amazon WebView SDK
Download and extract the Amazon WebView SDK zip file from the Amazon Developer Portal.
Copy awv_interface.jar from the unzipped folder into the amazon-fireos directory found in Cordova's global working directory. Note: You'll need to create the libs/ folder manually.
$ mkdir ~/.cordova/lib/amazon-fireos/cordova/3.4.0/libs $ cp awv_interface.jar ~/.cordova/lib/amazon-fireos/cordova/3.4.0/libs/
> mkdir %USERPROFILE%\.cordova\lib\amazon-fireos\cordova\3.4.0\libs > cp awv_interface.jar %USERPROFILE%\.cordova\lib\amazon-fireos\cordova\3.4.0\libs
4. Create Cordova Project
Create project. Open a command line/terminal in a directory where you'd like to have your project stored and run the following commands to create a project and add the files needed to build for Amazon Fire OS:
$ cordova create hello com.example.hello HelloWorld
Add Amazon Fire OS platform. Change into the newly created project directory and add the files needed for the amazon-fireos platform target.
$ cd hello $ cordova platform add amazon-fireos
Add support for Android devices if needed. If your app is going to be used on non-Fire OS devices running Android, you can provide a fallback to the stock Android WebView engine by adding the awv_android_factory.jar file found in the AWV SDK bundle into your Cordova project under the platform libraries folder. For example:
Adding the code above will allow you to submit the app to the Amazon Appstore and target non-Kindle Fire devices as well as all Kindle Fire devices.
Build and deploy your project. Make sure that USB debugging is enabled on your device as described on the Android Developer Site, and use a mini USB cable to plug it into your system. (Note: Currently, testing via an emulator is not supported for Amazon WebView based apps.)
Then you can build and deploy the app to the device with the following single command:
$ cordova run
What You Can Do Now
To learn more, follow these links (some of which will take you to third-party sites):