http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/21c8e8f0/www/docs/en/6.x/guide/next/index.md ---------------------------------------------------------------------- diff --git a/www/docs/en/6.x/guide/next/index.md b/www/docs/en/6.x/guide/next/index.md new file mode 100644 index 0000000..2bdf90d --- /dev/null +++ b/www/docs/en/6.x/guide/next/index.md @@ -0,0 +1,220 @@ +--- +license: > + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +title: Next Steps +--- + +# Next Steps + +For developers who have an understanding of how to use the Cordova CLI and make use of plugins, there are a few things you may want to consider researching next to build better, more performant Cordova applications. The following document offers advice on various topics relating to best practices, testing, upgrades, and other topics, but is not meant to be prescriptive. Consider this your launching point for your growth as a Cordova developer. Also, if you see something that can be improved, please [contribute](http://cordova.apache.org/#contribute)! + +This guide contains the following topics: + +* Best Practices +* Handling Upgrades +* Testing Cordova apps +* Debugging Cordova apps +* User Interface +* Special Considerations +* Keeping Up +* Getting Help + +# Best Practices Cordova app development + +## 1) SPA Is Your Friend + +First and foremost - your Cordova applications should adopt the SPA (Single Page Application) design. Loosely defined, a SPA is a client-side application that is run from one request of a web page. The user loads an initial set of resources (HTML, CSS, and JavaScript) and further updates (showing a new view, loading data) is done via AJAX. SPAs are commonly used for more complex client-side applications. GMail is a great example of this. After you load GMail, mail views, editing, and organization are all done by updating the DOM instead of actually leaving the current page to load a completely new one. + +Using a SPA can help you organize your application in a more efficient manner, but it also has specific benefits for Cordova applications. A Cordova application must wait for the [deviceready](../../cordova/events/events.deviceready.html) event to fire before any plugins may be used. If you do not use a SPA, and your user clicks to go from one page to another, you will have to wait for [deviceready](../../cordova/events/events.deviceready.html) to fire again before you make use of a plugin. This is easy to forget as your application gets larger. + +Even if you choose not to use Cordova, creating a mobile application without using a single page architecture will have serious performance implications. This is because navigating between pages will require scripts, assets, etc., to be reloaded. Even if these assets are cached, there will still be performance issues. + +Examples of SPA libraries you can use in your Cordova applications are: + +* [AngularJS](http://angularjs.org) +* [EmberJS](http://emberjs.com) +* [Backbone](http://backbonejs.org) +* [Kendo UI](http://www.telerik.com/kendo-ui) +* [Monaca](http://monaca.mobi/en/) +* [ReactJS](http://facebook.github.io/react/) +* [Sencha Touch](http://www.sencha.com/products/touch/) +* [jQuery Mobile](http://jquerymobile.com) + +And many, many, more. + +## 2) Performance Considerations + +One of the biggest mistakes a new Cordova developer can make is to assume that the performance they get on a desktop machine is the same they will get on a mobile device. While our mobile devices have gotten more powerful every year, they still lack the power and performance of a desktop. Mobile devices typically have much less RAM and a GPU that is a far cry from their desktop (or even laptop) brethren. A full list of tips here would be too much, but here are a few things to keep in mind (with a list of longer resources at the end for further research). + +**Click versus Touch** - The biggest and simplest mistake you can make is to use click events. While these "work" just fine on mobile, most devices impose a 300ms delay on them in order to distinguish between a touch and a touch "hold" event. Using `touchstart`, or `touchend`, will result in a dramatic improvement - 300ms doesn't sound like much, but it can result in jerky UI updates and behavior. You should also consider the fact that âtouchâ events are not supported on non-webkit browsers, see [CanIUse](http://caniuse.com/#search=touch). In order to deal with these limitations, you can checkout various libraries like HandJS and Fastouch. + +**CSS Transitions versus DOM Manipulation** - Using hardware accelerated CSS transitions will be dramatically better than using JavaScript to create animations. See the list of resources at the end of this section for examples. + +**Networks Suck** - Ok, networks don't always suck, but the latency of mobile networks, even good mobile networks, is far worse than you probably think. A desktop app that slurps down 500 rows of JSON data, every 30 seconds, will be both slower on a mobile device as well as a battery hog. Keep in mind that Cordova apps have multiple ways to persist data in the app (LocalStorage and the file system for example). Cache that data locally and be cognizant of the amount of data you are sending back and forth. This is an especially important consideration when your application is connected over a cellular network. + +**Additional Performance Articles and Resources** + +* ["You half assed it"](http://sintaxi.com/you-half-assed-it) +* ["Top Ten Performance Tips for PhoneGap and Hybrid Apps"](http://coenraets.org/blog/2013/10/top-10-performance-techniques-for-phonegap-and-hybrid-apps-slides-available/) +* ["Fast Apps and Sites with JavaScript"][1] + + [1]: https://channel9.msdn.com/Events/Build/2013/4-313 + +## 3) Recognize and Handle Offline Status + +See the previous tip about networks. Not only can you be on a slow network, it is entirely possible for your application to be completely offline. Your application should handle this in an intelligent manner. If your application does not, people will think your application is broken. Given how easy it is to handle (Cordova supports listening for both an offline and online event), there is absolutely no reason for your application to not respond well when run offline. Be sure to test (see the Testing section below) your application and be sure to test how your application handles when you start in one state and then switch to another. + +Note that the online and offline events, as well as the Network Connection API is not perfect. You may need to rely on using an XHR request to see if the device is truly offline or online. At the end of the day, be sure add some form of support for network issues - in fact, the Apple store (and probably other stores) will reject apps that donât properly handle offline/online states. For more discussion on this topic, see +["Is This Thing On?"](http://blogs.telerik.com/appbuilder/posts/13-04-23/is-this-thing-on-%28part-1%29) + +# Handling Upgrades + +## Upgrading Cordova Projects + +If your existing project was created using Cordova 3.x, you can upgrade the project by issuing the following: + + cordova platform update platform-name ios, android, etc. + +If your existing project was created under a version prior to Cordova 3.x, it would probably be best to create a new Cordova 3.x project, and then copy your existing projectâs code and assets to the new project. Typical steps: + +* Create a new Cordova 3.x project (cordova create ...) +* Copy the www folder from your old project to the new project +* Copy any configuration settings from the old project to the new project +* Add any plugins used in the old project to the new project +* Build your project +* Test, test, test! + +Regardless of the project's prior version, it is absolutely critical that you read up on what was changed in the updated version, as the update may break your code. The best place to find this information will be in the release notes published both in the repositories and on the Cordova blog. You will want to test your app thoroughly in order to verify that it is working correctly after you perform the update. + +Note: some plugins may not be compatible with the new version of Cordova. If a plugin is not compatible, you may be able to find a replacement plugin that does what you need, or you may need to delay upgrading your project. Alternatively, alter the plugin so that it does work under the new version and contribute back to the community. + +## Plugin Upgrades +As of Cordova 3.4, there is no mechanism for upgrading changed plugins using a single command. Instead, remove the plugin and add it back to your project, and the new version will be installed: + + cordova plugin rm com.some.plugin + cordova plugin add com.some.plugin + +Be sure to check the updated plugin's documentation, as you may need to adjust your code to work with the new version. Also, double check that the new version of the plugin works with your projectâs version of Cordova. + +Always test your apps to ensure that installing the new plugin has not broken something that you did not anticipate. + +If your project has a lot of plugins that you need updated, it might save time to create a shell or batch script that removes and adds the plugins with one command. + +# Testing Cordova apps + +Testing your applications is super important. The Cordova team uses Jasmine but any web friendly unit testing solution will do. + +## Testing on a simulator vs. on a real device + +Itâs not uncommon to use desktop browsers and device simulators/emulators when developing a Cordova application. However, it is incredibly important that you test your app on as many physical devices as you possibly can: + +* Simulators are just that: simulators. For example, your app may work in the iOS simulator without a problem, but it may fail on a real device (especially in certain circumstances, such as a low memory state). Or, your app may actually fail on the simulator while it works just fine on a real device. +* Emulators are just that: emulators. They do not represent how well your app will run on a physical device. For example, some emulators may render your app with a garbled display, while a real device has no problem. (If you do encounter this problem, disable the host GPU in the emulator.) +* Simulators are generally faster than your physical device. Emulators, on the other hand, are generally slower. Do not judge the performance of your app by how it performs in a simulator or an emulator. Do judge the performance of your app by how it runs on a spectrum of real devices. +* It's impossible to get a good feel for how your app responds to your touch by using a simulator or an emulator. Instead, running the app on a real device can point out problems with the sizes of user interface elements, responsiveness, etc. +* Although it would be nice to be able to test only on one device per platform, it is best to test on many devices sporting many different OS versions. For example, what works on your particular Android smartphone may fail on another Android device. What works on an iOS 7 device may fail on an iOS 6 device. + +It is, of course, impossible to test on every possible device on the market. For this reason, itâs wise to recruit many testers who have different devices. Although they wonât catch every problem, chances are good that they will discover quirks and issues that you would never find alone. + +Tip: It is possible on Android Nexus devices to easily flash different versions of Android onto the device. This simple process will allow you to easily test your application on different levels of Android with a single device, without voiding your warranty or requiring you to âjailbreakâ or ârootâ your device. The Google Android factory images and instructions are located at: https://developers.google.com/android/nexus/images#instructions + +# Debugging Cordova apps + +Debugging Cordova requires some setup. Unlike a desktop application, you can't simply open dev tools on your mobile device and start debugging, luckily there are some great alternatives. + +## iOS Debugging + +### Xcode +With Xcode you can debug the iOS native side of your Cordova application. Make sure the Debug Area is showing (View -> Debug Area). Once your app is running on the device (or simulator), you can view log output in the debug area. This is where any errors or warnings will print. You can also set breakpoints within the source files. This will allow you to step through the code one line at a time and view the state of the variables at that time. The state of the variables is shown in the debug area when a breakpoint is hit. Once your app is up and running on the device, you can bring up Safari's web inspector (as described below) to debug the webview and js side of your application. For more details and help, see the Xcode guide: [Xcode Debugging Guide](https://developer.apple.com/library/mac/documentation/ToolsLanguages/Conceptual/Xcode_Overview/DebugYourApp/DebugYourApp.html#//apple_ref/doc/uid/TP40010215-CH18-SW1) + +### Safari Remote Debugging with Web Inspector +With Safari's web inspector you can debug the webview and js code in your Cordova application. This works only on OSX and only with iOS 6 (and higher). It uses Safari to connect to your device (or the simulator) and will connect the browser's dev tools to the Cordova application. You get what you expect from dev tools - DOM inspection/manipulation, a JavaScript debugger, network inspection, the console, and more. Like Xcode, with Safari's web inspector you can set breakpoints in the JavaScript code and view the state of the variables at that time. You can view any errors, warnings or messages that are printed to the console. You can also run JavaScript commands directly from the console as your app is running. For more details on how to set it up and what you can do, see this excellent blog post: [http://moduscreate.com/enable-remote-web-inspector-in-ios-6/](http://moduscreate.com/enable-remote-web-inspector-in-ios-6/) and this guide: [Safari Web Inspector Guide](https://developer.a pple.com/library/safari/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/Introduction/Introduction.html) + +## Chrome Remote Debugging +Virtually the same as the Safari version, this works with Android only but can be used from any desktop operating system. It requires a minimum of Android 4.4 (KitKat), minimum API level of 19, and Chrome 30+ (on the desktop). Once connected, you get the same Chrome Dev Tools experience for your mobile applications as you do with your desktop applications. Even better, the Chrome Dev Tools have a mirror option that shows your app running on the mobile device. This is more than just a view - you can scroll and click from dev tools and it updates on the mobile device. More details on Chrome Remote Debugging may be found here: [https://developers.google.com/chrome/mobile/docs/debugging](https://developers.google.com/chrome/mobile/docs/debugging) + +It is possible to use Chrome Dev Tools to inspect iOS apps, through a WebKit proxy: [https://github.com/google/ios-webkit-debug-proxy/](https://github.com/google/ios-webkit-debug-proxy/) + +## Ripple +Ripple is a desktop based emulator for Cordova projects. Essentially it lets you run a Cordova application in your desktop application and fake various Cordova features. For example, it lets you simulate the accelerometer to test shake events. It fakes the camera API by letting you select a picture from your hard drive. Ripple lets you focus more on your custom code rather than worrying about Cordova plugins. You can find out more about Ripple here: [http://ripple.incubator.apache.org/](http://ripple.incubator.apache.org/) + +## Weinre +Weinre creates a local server that can host a remote debug client for your Cordova applications. After you've installed and started it up, you copy a line of code into your Cordova application and then restart it. You can then open a dev tool panel on your desktop to work with the application. Weinre is not quite as fancy as Chrome and Safari Remote debugging but has the benefit of working with a much greater range of operating systems and platforms. More information may be found here: [http://people.apache.org/~pmuellr/weinre/docs/latest/](http://people.apache.org/~pmuellr/weinre/docs/latest/) + +## Other Options + +* BlackBerry 10 supports debugging as well: [Documentation]( https://developer.blackberry.com/html5/documentation/v2_0/debugging_using_web_inspector.html) +* You can debug using Firefox App Manager as well, see [this blog post](https://hacks.mozilla.org/2014/02/building-cordova-apps-for-firefox-os/) and this +[MDN article](https://developer.mozilla.org/en-US/Apps/Tools_and_frameworks/Cordova_support_for_Firefox_OS#Testing_and_debugging). +* For more examples and explanation of the above debugging tips, see: [http://developer.telerik.com/featured/a-concise-guide-to-remote-debugging-on-ios-android-and-windows-phone/](http://developer.telerik.com/featured/a-concise-guide-to-remote-debugging-on-ios-android-and-windows-phone/) + +# User Interface + +Building a Cordova application that looks nice on mobile can be a challenge, especially for developers. Many people chose to use a UI framework to make this easier. Here is a short list of options you may want to consider. + +* [jQuery Mobile](http://jquerymobile.com) - jQuery Mobile automatically enhances your layout for mobile optimization. It also handles creating a SPA for you automatically. +* [ionic](http://ionicframework.com/) - This powerful UI framework actually has its own CLI to handle project creation. +* [Ratchet](http://goratchet.com/) - Brought to you by the people who created Bootstrap. +* [Kendo UI](http://www.telerik.com/kendo-ui) - Open source UI and application framework from Telerik. +* [Topcoat](http://topcoat.io) +* [ReactJS](http://facebook.github.io/react/) + +When building your user interface, it is important to think about all platforms that you are targeting and the differences between the userâs expectations. For example, an Android application that has an iOS-style UI will probably not go over well with users. This sometimes is even enforced by the various application stores. Because of this, it is important that you respect the conventions of each platform and therefore are familiar with the various Human Interface Guidelines: + +* [iOS](https://developer.apple.com/library/ios/documentation/userexperience/conceptual/MobileHIG/index.html) +* [Android](https://developer.android.com/designWP8) +* [Windows Phone](http://dev.windowsphone.com/en-us/design/library) + +## Additional UI Articles and Resources + +Although browser engines become more and more standards complaint, we still live in a prefixed world (-webkit and -ms.) The following article is valuable when developing UIâs in for cross browser apps: [http://blogs.windows.com/windows_phone/b/wpdev/archive/2012/11/15/adapting-your-webkit-optimized-site-for-internet-explorer-10.aspx](http://blogs.windows.com/windows_phone/b/wpdev/archive/2012/11/15/adapting-your-webkit-optimized-site-for-internet-explorer-10.aspx) + +# Special Considerations + +Although Cordova makes cross-platform development easier, it's just not possible to provide 100% isolation from the underlying native platform. So do be aware of restrictions. + +## Platform Quirks + +While reading the documentation, look for sections which outline different behaviors or requirements on multiple platforms. If present, these would be in a section titled "Android Quirks", "iOS Quirks", etc. Read through these quirks and be aware of them as you work with Cordova. + +## Loading Remote Content + +Invoking Cordova JavaScript functions from a remotely-loaded HTML page (an HTML page not stored locally on the device) is an unsupported configuration. This is because Cordova was not designed for this, and the Apache Cordova community does no testing of this configuration. While it can work in some circumstances, it is not recommended nor supported. There are challenges with the same origin policy, keeping the JavaScript and native portions of Cordova synchronized at the same version (since they are coupled via private APIs which may change), the trustworthiness of remote content calling native local functions, and potential app store rejection. + +The display of remotely-loaded HTML content in a webview should be done using Cordova's InAppBrowser. The InAppBrowser is designed so that JavaScript running there does not have access to the Cordova JavaScript APIs for the reasons listed above. Please refer to the [Security Guide](../appdev/security/index.html). + +# Keeping Up + +Here are a few ways to keep up to date with Cordova. + +* Subscribe to the [Cordova blog](http://cordova.apache.org/#news). +* Subscribe to the [developer list](http://cordova.apache.org/#mailing-list). Note - this is not a support group! Rather this is a place where development of Cordova is discussed. + +# Getting Help + +The following links are the best places to get help for Cordova: + +* StackOverflow: [http://stackoverflow.com/questions/tagged/cordova](http://stackoverflow.com/questions/tagged/cordova) +By using the Cordova tag, you can view and browse all Cordova questions. Note that StackOverflow automatically converts the "Phonegap" tag to "Cordova", so this way you will be able to access historical questions as well +* PhoneGap Google Group: [https://groups.google.com/forum/#!forum/phonegap](https://groups.google.com/forum/#!forum/phonegap) +This Google Group was the old support forum when Cordova was still called PhoneGap. While there are still a lot of Cordova users that frequently visit this group, the Cordova community has expressed an interest in focusing less on this group and instead using StackOverflow for support +* Meetup: [http://phonegap.meetup.com](http://phonegap.meetup.com) - +Consider finding a local Cordova/PhoneGap meetup group + +
http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/21c8e8f0/www/docs/en/6.x/guide/overview/index.md ---------------------------------------------------------------------- diff --git a/www/docs/en/6.x/guide/overview/index.md b/www/docs/en/6.x/guide/overview/index.md new file mode 100644 index 0000000..146e358 --- /dev/null +++ b/www/docs/en/6.x/guide/overview/index.md @@ -0,0 +1,160 @@ +--- +license: > + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +title: Overview +--- + +# Overview + +Apache Cordova is an open-source mobile development framework. It allows you +to use standard web technologies such as HTML5, CSS3, and JavaScript +for cross-platform development, avoiding each mobile platforms' native +development language. Applications execute within wrappers targeted +to each platform, and rely on standards-compliant API bindings to +access each device's sensors, data, and network status. + +Apache Cordova graduated in October 2012 as a top level project within the Apache Software Foundation (ASF). Through the ASF, future Cordova development will ensure open stewardship of the project. It will always remain free and open source under the Apache License, Version 2.0. Visit [cordova.apache.org](http://cordova.apache.org) for more information. + +Use Apache Cordova if you are: + +* a mobile developer and want to extend an application across more + than one platform, without having to re-implement it with each + platform's language and tool set. + +* a web developer and want to deploy a web app that's packaged for + distribution in various app store portals. + +* a mobile developer interested in mixing native application + components with a _WebView_ (special browser window) that can access + device-level APIs, or if you want to develop a plugin interface + between native and WebView components. + +## Basic Components + +Apache Cordova applications rely on a common `config.xml` file that provides +information about the app and specifies parameters affecting how it +works, such as whether it responds to orientation shifts. This file +adheres to the W3C's +[Packaged Web App](http://www.w3.org/TR/widgets/), +or _widget_, specification. + +The application itself is implemented as a web page, by default a local +file named _index.html_, that references whatever CSS, JavaScript, +images, media files, or other resources are necessary for it to run. +The app executes as a _WebView_ within the native application wrapper, +which you distribute to app stores. + +The Cordova-enabled WebView may provide the application with its +entire user interface. On some platforms, it can also be a component +within a larger, hybrid application that mixes the WebView with native +application components. (See [Embedding WebViews](../hybrid/webviews/index.html) for details.) + +A _plugin_ interface is available for Cordova and native components to +communicate with each other. This enables you to invoke native code +from JavaScript. Ideally, the JavaScript APIs to that native code are +consistent across multiple device platforms. As of version 3.0, plugins provide +bindings to standard device APIs. Third-party plugins provide +additional bindings to features not necessarily available on all +platforms. You can find these third-party plugins in the +[plugin registry](http://plugins.cordova.io) and use them in your +application. You can also develop your own plugins, as described in the +[Plugin Development Guide](../hybrid/plugins/index.html). Plugins may be necessary, for example, to +communicate between Cordova and custom native components. + +__NOTE__: As of version 3.0, when you create a Cordova project it does not have +any plugins present. This is the new default behavior. Any plugins you +desire, even the core plugins, must be explicitly added. + +Cordova does not provide any UI widgets or MV* frameworks. Cordova provides +only the runtime in which those can execute. If you wish to use UI widgets +and/or an MV* framework, you will need to select those and include them in +your application yourself as third-party material. + +## Development Paths + +As of version 3.0, you can use two basic workflows to create a mobile +app. While you can often use either workflow to accomplish the same +task, they each offer advantages: + +- __Cross-platform (CLI) workflow__: Use this workflow if you want your app + to run on as many different mobile operating systems as possible, + with little need for platform-specific development. This workflow + centers around the `cordova` utility, otherwise known as the Cordova + _CLI_, that was introduced with Cordova 3.0. The CLI is a high-level + tool that allows you to build projects for many platforms at once, + abstracting away much of the functionality of lower-level shell + scripts. The CLI copies a common set of web assets into + subdirectories for each mobile platform, makes any necessary + configuration changes for each, runs build scripts to generate + application binaries. The CLI also provides a common interface to + apply plugins to your app. For more details on the CLI, see The + Command-Line Interface. Unless you have a need for the platform-centered + workflow, the cross-platform workflow is recommended. + +- __Platform-centered workflow__: Use this workflow if you want to + focus on building an app for a single platform and need to be able + to modify it at a lower level. You need to use this approach, for + example, if you want your app to mix custom native components with + web-based Cordova components, as discussed in [Embedding WebViews](../hybrid/webviews/index.html). + As a rule of thumb, use this workflow if you need to modify the + project within the SDK. This workflow relies on a set of + lower-level shell scripts that are tailored for each supported + platform, and a separate Plugman utility that allows you to apply + plugins. While you can use this workflow to build cross-platform + apps, it is generally more difficult because the lack of a + higher-level tool means separate build cycles and plugin + modifications for each platform. Still, this workflow allows you + greater access to development options provided by each SDK, and is + essential for complex hybrid apps. See the various [Platform Guides](../platforms/index.html) + for details on each platform's available shell utilities. + +When first starting out, it may be easiest to use the cross-platform +workflow to create an app, as described in [The Command-Line Interface](../cli/index.html). +You then have the option to switch to a platform-centered workflow if +you need the greater control the SDK provides. Lower-level shell +utilities are available at +[cordova.apache.org](http://cordova.apache.org) in a separate +distribution than the CLI. For projects initially generated by the +CLI, these shell tools are also available in the project's various +`platforms/*/cordova` directories. + +__NOTE__: Once you switch from the CLI-based workflow to one centered +around the platform-specific SDKs and shell tools, you can't go back. +The CLI maintains a common set of cross-platform source code, which on +each build it uses to write over platform-specific source code. To +preserve any modifications you make to the platform-specific assets, +you need to switch to the platform-centered shell tools, which ignore +the cross-platform source code, and instead relies on the +platform-specific source code. + +## Installing Cordova + +The installation of Cordova will differ depending on the workflow above +you choose: + + * Cross-platform workflow: see [The Command-Line Interface](../cli/index.html). + + * Platform-centered workflow: see the [Platform Guides](../platforms/index.html). + +After installing Cordova, it is recommended that you review the [Platform Guides](../platforms/index.html) +for the mobile platforms that you will be developing for. It is also +recommended that you also review the [Privacy Guide](../appdev/privacy/index.html), [Security Guide](../appdev/security/index.html), and +[Next Steps](../next/index.html). For configuring Cordova, see [The config.xml File](../../config_ref/index.html). +For accessing native function on a device from JavaScript, refer +to the [Plugin APIs](../../cordova/plugins/pluginapis.html). And refer to the other included guides as necessary. http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/21c8e8f0/www/docs/en/6.x/guide/platforms/amazonfireos/config.md ---------------------------------------------------------------------- diff --git a/www/docs/en/6.x/guide/platforms/amazonfireos/config.md b/www/docs/en/6.x/guide/platforms/amazonfireos/config.md new file mode 100644 index 0000000..8a99227 --- /dev/null +++ b/www/docs/en/6.x/guide/platforms/amazonfireos/config.md @@ -0,0 +1,84 @@ +--- +license: > + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +title: Amazon Fire OS Configuration +--- + +# Amazon Fire OS Configuration + +The `config.xml` file controls an app's basic settings that apply +across each application and CordovaWebView instance. This section +details preferences that only apply to Amazon Fire OS builds. See [The config.xml +File](config_ref_index.md.html#The%20config.xml%20File) for information on global configuration options. + +- `KeepRunning` (boolean, defaults to `true`): Determines whether the + application stays running in the background even after a `[pause](../../../cordova/events/events.pause.html)` + event fires. Setting this to `false` does not kill the app after a + `[pause](../../../cordova/events/events.pause.html)` event, but simply halts execution of code within the cordova + webview while the app is in the background. + + <preference name="KeepRunning" value="false"/> + +- `ErrorUrl` (URL, defaults to `null`): + If set, will display the referenced page upon an error in the application + instead of a dialog with the title "Application Error". + + <preference name="ErrorUrl" value="error.html"/> + +- `LoadingDialog` (string, defaults to `null`): If set, displays a dialog with + the specified title and message, and a spinner, when loading the first + page of an application. The title and message are separated by a comma + in this value string, and that comma is removed before the dialog is + displayed. + + <preference name="LoadingDialog" value="Please wait, the app is loading"/> + +- `LoadingPageDialog` (string, defaults to `null`): The same as `LoadingDialog`, + but for loading every page after the first page in the application. + + <preference name="LoadingPageDialog" value="Please wait, the data is loading"/> + +- `LoadUrlTimeoutValue` (number, default is `20000`): When loading a + page, the amount of time to wait before throwing a timeout error. + This example specifies 10 seconds rather than 20: + + <preference name="LoadUrlTimeoutValue" value="10000"/> + +- `SplashScreen`: The name of the file minus its extension in the + `res/drawable` directory. Various assets must share this common + name in various subdirectories. + + <preference name="SplashScreen" value="splash"/> + +- `SplashScreenDelay` (number, defaults to `5000`): The amount of + time the splash screen image displays. + + <preference name="SplashScreenDelay" value="10000"/> + +- `ShowTitle` (boolean, defaults to `false`): Show the title at the top + of the screen. + + <preference name="ShowTitle" value="true"/> + +- `LogLevel` (string, defaults to `ERROR`): Sets the minimum log level + through which log messages from your application will be filtered. Valid + values are `ERROR`, `WARN`, `INFO`, `DEBUG`, and `VERBOSE`. + + <preference name="LogLevel" value="VERBOSE"/> + http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/21c8e8f0/www/docs/en/6.x/guide/platforms/amazonfireos/index.md ---------------------------------------------------------------------- diff --git a/www/docs/en/6.x/guide/platforms/amazonfireos/index.md b/www/docs/en/6.x/guide/platforms/amazonfireos/index.md new file mode 100644 index 0000000..055f249 --- /dev/null +++ b/www/docs/en/6.x/guide/platforms/amazonfireos/index.md @@ -0,0 +1,195 @@ +--- +license: > + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +title: Amazon Fire OS Platform Guide +--- + +# Amazon Fire OS Platform Guide + +This guide shows how to set up your SDK development environment to +deploy Cordova apps for Amazon Fire OS devices, such as the Kindle Fire HDX. + +See the following for more detailed platform-specific information: + +* [Amazon Fire OS Configuration](config.html) +* [Amazon Fire OS WebViews](webview.html) +* [Amazon Fire OS Plugins](plugin.html) + +## Introduction + +By targeting the Amazon Fire OS platform, Cordova developers can create hybrid web apps that take advantage of the advanced web engine integrated into Kindle Fire devices. Amazon WebView API (AWV) is a Chromium-derived web runtime exclusive to Fire OS. A drop-in replacement for the WebView that comes with Android devices, AWV makes it possible to create better performing and more powerful hybrid web apps by providing support for a faster JavaScript engine (V8), remote debugging, and hardware optimizations for Kindle Fire devices including an accelerated 2D Canvas, and access to HTML5 features not supported by Androidâs built in WebView such as: CSS Calc, Form Validation, getUserMedia, IndexedDB, Web Workers, WebSockets and WebGL. + +For more information about the Amazon WebView API, please see the Amazon Developer Portal's [HTML5 Hybrid Apps page](https://developer.amazon.com/public/solutions/platforms/android-fireos/docs/building-and-testing-your-hybrid-app). For questions about getting started and other support issues, please see the Amazon Developer Portal [Forums - HTML5 Hybrid Apps](http://forums.developer.amazon.com/forums/category.jspa?categoryID=41). + + +## Requirements and Support + +Developing Cordova apps for Amazon Fire OS requires installation of a variety of support files, including everything needed for Android development, as well as the Amazon WebView SDK. Check the list below for the required installs: + +* [The Command-Line Interface](../../cli/index.html) +* [Android SDK](http://developer.android.com/sdk/) +* [Apache Ant](http://ant.apache.org) +* [Amazon WebView SDK](https://developer.amazon.com/public/solutions/platforms/android-fireos/docs/building-and-testing-your-hybrid-app) + +## Installation + + +### Android SDK and Apache Ant + +Install the Android SDK from +[developer.android.com/sdk](http://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. + +You'll need to run the Android SDK Manager (`android` from a command line) at least once before starting your Cordova project. Make sure to install the most recent version of the Android SDK Tools and SDK Platform **specifically API level 19**. Please see [Setting up your Development Environment](https://developer.amazon.com/public/resources/development-tools/ide-tools/tech-docs/01-setting-up-your-development-environment) on the Amazon Developer Portal for more information about setting up your development environment for Kindle Fire OS devices. + +Install the Apache Ant build tool by [downloading an Ant binary distribution](http://ant.apache.org/bindownload.cgi), unzipping into a directory you can refer to later. See the [Ant manual](http://ant.apache.org/manual/index.html) for more info. + +For Cordova command-line tools to work, you need to include the Android SDK's +`tools`, `platform-tools` and `apache-ant/bin` directories in your PATH environment. + +#### Mac/Linux Path + +On Mac, Linux or other Unix-like platforms, you can use a text editor to create or modify the +`~/.bash_profile` file, adding a line such as the following, depending +on where the SDK and Ant are installed: + + export PATH=${PATH}:/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools:/Development/apache-ant/bin + +This exposes SDK tools in newly opened terminal windows. Otherwise run +this to make them available in the current session: + + $ source ~/.bash_profile + +#### Windows Path + +To modify the PATH environment on Windows: + +* 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 and Ant, for example: + + ;C:\Development\adt-bundle\sdk\platform-tools;C:\Development\adt-bundle\sdk\tools;C:\Development\apache-ant\bin + +* Save the value and close both dialog boxes. + +* You will also need to enable Java. Open a command prompt and +type `java`, if it does not run, append the location of the Java binaries to your PATH as well. Make sure %JAVA_HOME% is pointing to installed JDK directory. You might have to add JAVA_HOME environment variable seperately. + + ;%JAVA_HOME%\bin + + +### Amazon WebView SDK + +In order to create Cordova apps using the Amazon Fire OS platform target, you'll need to download, unpack and install the Amazon WebView SDK support files. This step will only need to be done for your first Amazon Fire OS project. + +* Download the Amazon WebView SDK from the [Amazon Developer Portal](https://developer.amazon.com/public/solutions/platforms/android-fireos/docs/building-and-testing-your-hybrid-app). + +* Copy `awv_interface.jar` from the downloaded SDK to Cordova's working directory. Create commonlibs(shown below) folder if it doesn't exist: + + **Mac/Linux:** + `~/.cordova/lib/commonlibs/` + + **Windows:** + `%USERPROFILE%\.cordova\lib\commonlibs` + + +## Create New Project for Amazon Fire OS + +Use the `cordova` utility to set up a new project, as described in The +Cordova [The Command-Line Interface](../../cli/index.html). For example, in a source-code directory: + + $ cordova create hello com.example.hello "HelloWorld" + $ cd hello + $ cordova platform add amazon-fireos + $ cordova build + +***Note:*** The first time the amazon-fireos platform is installed on your system, it will download the appropriate files to the Cordova working directory, but will then fail as it is missing the AWV SDK support files (see above). Follow the instructions above to install the `awv_interface.jar`, then remove and re-add the amazon-fireos platform to your project. This step will only need to be done for first Amazon Fire OS project. + + +## Deploy to Device + +To push an app directly to the device, make sure USB debugging is enabled on your device as described on the +[Android Developer Site](http://developer.android.com/tools/device.html), +and use a mini USB cable to plug it into your system. + +You can push the app to the device from the command line: + + $ cordova run amazon-fireos + +Alternately within Eclipse, right-click the project and choose __Run +As → Android Application__. + +__Note__: Currently, testing via an emulator is not supported for Amazon WebView based apps, additionally the Amazon WebView API is only available on Fire OS devices. For more information, please see the [Amazon WebView API SDK](https://developer.amazon.com/public/solutions/platforms/android-fireos/docs/building-and-testing-your-hybrid-app) documentation. + +### Run Flags + +The run command accepts optional parameters as specified in the Cordova Command Line Interface document, Fire OS also accepts an additional `--debug` flag which will enable Chromium's Developer Tools for remote web debugging. + +To use Developer Tools, enter: + + $ cordova run --debug amazon-fireos + +This will enable the tools on the running client. You can then connect to the client by port forwarding using the Android Debug Bridge (adb) referring to the app's package name. + +For example: + + adb forward tcp:9222 localabstract:com.example.helloworld.devtools + +You can then use the DevTools via a Chromium-based browser by navigating to: `http://localhost:9222`. + +### Optional Eclipse support + +Once created, you can use the Eclipse that comes along with the Android SDK to modify the project. Beware that modifications made through Eclipse will be overwritten if you continue to use Cordova command line tools. + +* Launch the __Eclipse__ application. + +* Select the __New Project__ menu item. + +* Choose __Android Project from Existing Code__ from the resulting dialog box, and press __Next__: + ![]({{ site.baseurl }}/static/img/guide/platforms/android/eclipse_new_project.png) + +* Navigate to `hello`, or whichever directory you created for the project, then to the `platforms/amazon-fireos` subdirectory. + +* Eclipse will show you hello and hello-CorddovaLib - 2 projects to be added. Add both. + +* Press __Finish__. + +Once the Eclipse window opens, a red __X__ may appear to indicate +unresolved problems. If so, follow these additional steps: + +* Right-click on the project directory. + +* In the resulting __Properties__ dialog, select __Android__ from the navigation pane. + +* For the project build target, select the highest Android API level (currently API Level 19) you have installed. + +* Click __OK__. + +* Select __Clean__ from the __Project__ menu. This should correct all the errors in the project. + http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/21c8e8f0/www/docs/en/6.x/guide/platforms/amazonfireos/plugin.md ---------------------------------------------------------------------- diff --git a/www/docs/en/6.x/guide/platforms/amazonfireos/plugin.md b/www/docs/en/6.x/guide/platforms/amazonfireos/plugin.md new file mode 100644 index 0000000..d4fdac4 --- /dev/null +++ b/www/docs/en/6.x/guide/platforms/amazonfireos/plugin.md @@ -0,0 +1,103 @@ +--- +license: > + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +title: Amazon Fire OS Plugins +--- + +# Amazon Fire OS Plugins + +Follow the instructions provided in the [Android Plugins](../android/plugin.html) Guide for an overview of developing custom plugins. + +## Echo Amazon Fire OS Plugin Example + +To match the JavaScript interface's _echo_ feature described in +Application Plugins, use the `plugin.xml` to inject a `feature` +specification to the local platform's `config.xml` file: + + <platform name="amazon-fireos"> + <config-file target="config.xml" parent="/*"> + <feature name="Echo"> + <param name="android-package" value="org.apache.cordova.plugin.Echo"/> + </feature> + </config-file> + </platform> + +Then add the following to the +`src/org/apache/cordova/plugin/Echo.java` file: + + package org.apache.cordova.plugin; + + import org.apache.cordova.CordovaPlugin; + import org.apache.cordova.CallbackContext; + + import org.json.JSONArray; + import org.json.JSONException; + import org.json.JSONObject; + + /** + * This class echoes a string called from JavaScript. + */ + public class Echo extends CordovaPlugin { + + @Override + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { + if (action.equals("echo")) { + String message = args.getString(0); + this.echo(message, callbackContext); + return true; + } + return false; + } + + private void echo(String message, CallbackContext callbackContext) { + if (message != null && message.length() > 0) { + callbackContext.success(message); + } else { + callbackContext.error("Expected one non-empty string argument."); + } + } + } + +If you want to reuse Android Plugin code for the Amazon Fire OS platform then modify the plugin.xml to point to the `android` specific source file. For example, + + <platform name="amazon-fireos"> + <config-file target="config.xml" parent="/*"> + <feature name="Echo"> + <param name="android-package" value="org.apache.cordova.plugin.Echo"/> + </feature> + </config-file> + <source-file src="src/android/Echo.java" target-dir="src/org/apache/cordova/plugin" /> + </platform> + +If you want to write a customized plugin for the Amazon Fire OS platform then create a folder named `amazon` under your plugin src/ folder and modify the plugin.xml to point to the `amazon` specific source file. For example, + + <platform name="amazon-fireos"> + <config-file target="config.xml" parent="/*"> + <feature name="Echo"> + <param name="android-package" value="org.apache.cordova.plugin.Echo"/> + </feature> + </config-file> + <source-file src="src/amazon/Echo.java" target-dir="src/org/apache/cordova/plugin" /> + </platform> + +## Using Amazon WebView in your plugin + +Cordova for Amazon Fire OS makes use of custom Amazon WebView that is built on the open-source Chromium project. It is GPU accelerated and optimized for fluid performance on Kindle Fire. + +To understand how to best use Amazon WebView in your project, check out the [Amazon Developer Portal](https://developer.amazon.com/sdk/fire/IntegratingAWV.html). http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/21c8e8f0/www/docs/en/6.x/guide/platforms/amazonfireos/webview.md ---------------------------------------------------------------------- diff --git a/www/docs/en/6.x/guide/platforms/amazonfireos/webview.md b/www/docs/en/6.x/guide/platforms/amazonfireos/webview.md new file mode 100644 index 0000000..4c018e5 --- /dev/null +++ b/www/docs/en/6.x/guide/platforms/amazonfireos/webview.md @@ -0,0 +1,130 @@ +--- +license: > + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +title: Amazon Fire OS WebViews +--- + +# Amazon Fire OS WebViews + +Beginning with 3.3.0, you can use Cordova as a component in Amazon Fire OS applications. Amazon Fire OS refers to this component as `CordovaWebView`. `CordovaWebView` extends Amazon WebView that is built on the open source Chromium Project. By leveraging this feature, your web apps can utilize the latest HTML5 web standards running in a modern web runtime engine. + +If you're unfamiliar with Amazon Fire OS, you should first familiarize +yourself with the [Amazon Fire OS Platform Guide](index.html) and have the latest SDKs installed before you attempt the more unusual development option of embedding a WebView. + +## Prerequisites + +* Cordova 3.3.0 or greater + +* Android SDK updated to the latest SDK + +* Amazon WebView SDK + +## Guide to using CordovaWebView in a Amazon Fire OS Project + +1. To follow these instructions, make sure you have the latest Cordova + distribution. Download it from + [cordova.apache.org](http://cordova.apache.org) and unzip its + Amazon Fire OS package. + +2. Download and expand the [Amazon WebView SDK](https://developer.amazon.com/sdk/fire/IntegratingAWV.html#installawv) , then copy the awv_interface.jar into `/framework/libs` directory. Create a libs/ folder if it doesn't exist. + +3. Navigate to the package's `/framework` directory and run + `ant jar`. It creates the Cordova `.jar` file, formed as + `/framework/cordova-x.x.x.jar`. + +4. Copy the `.jar` file into the Android project's `/libs` directory. + +5. Add the following to the application's `/res/xml/main.xml` file, + with the `layout_height`, `layout_width` and `id` modified to suit + the application: + + <org.apache.cordova.CordovaWebView + android:id="@+id/tutorialView" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + +6. Modify your activity so that it implements the `CordovaInterface`. You should implement the included methods. You may wish to copy them from `/framework/src/org/apache/cordova/CordovaActivity.java`, or implement them on your own. The code fragment below shows a basic application that uses the interface. Note how the referenced view id matches the `id` attribute specified in the XML fragment shown above: + + public class CordovaViewTestActivity extends Activity implements CordovaInterface { + CordovaWebView cwv; + /* Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + cwv = (CordovaWebView) findViewById(R.id.tutorialView); + Config.init(this); + cwv.loadUrl(Config.getStartUrl()); + } + +If you use the camera, you should also implement this: + + @Override + public void setActivityResultCallback(CordovaPlugin plugin) { + this.activityResultCallback = plugin; + } + /** + * Launch an activity for which you would like a result when it finished. When this activity exits, + * your onActivityResult() method is called. + * + * @param command The command object + * @param intent The intent to start + * @param requestCode The request code that is passed to callback to identify the activity + */ + public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) { + this.activityResultCallback = command; + this.activityResultKeepRunning = this.keepRunning; + + // If multitasking turned on, then disable it for activities that return results + if (command != null) { + this.keepRunning = false; + } + + // Start activity + super.startActivityForResult(intent, requestCode); + } + + @Override + /** + * Called when an activity you launched exits, giving you the requestCode you started it with, + * the resultCode it returned, and any additional data from it. + * + * @param requestCode The request code originally supplied to startActivityForResult(), + * allowing you to identify who this result came from. + * @param resultCode The integer result code returned by the child activity through its setResult(). + * @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). + */ + protected void onActivityResult(int requestCode, int resultCode, Intent intent) { + super.onActivityResult(requestCode, resultCode, intent); + CordovaPlugin callback = this.activityResultCallback; + if (callback != null) { + callback.onActivityResult(requestCode, resultCode, intent); + } + } + +Finally, remember to add the thread pool, otherwise the plugins have no threads to run on: + + @Override + public ExecutorService getThreadPool() { + return threadPool; + } + +7. Copy your application's HTML and JavaScript files to your Amazon Fire OS project's `/assets/www` directory. + +8. Copy `config.xml` from `/framework/res/xml` to your project's `/res/xml` directory. http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/21c8e8f0/www/docs/en/6.x/guide/platforms/android/config.md ---------------------------------------------------------------------- diff --git a/www/docs/en/6.x/guide/platforms/android/config.md b/www/docs/en/6.x/guide/platforms/android/config.md new file mode 100644 index 0000000..6a120ad --- /dev/null +++ b/www/docs/en/6.x/guide/platforms/android/config.md @@ -0,0 +1,125 @@ +--- +license: > + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +title: Android Configuration +--- + +# Android Configuration + +The `config.xml` file controls an app's basic settings that apply +across each application and CordovaWebView instance. This section +details preferences that only apply to Android builds. See [The config.xml +File](config_ref_index.md.html#The%20config.xml%20File) for information on global configuration options. + +- `KeepRunning` (boolean, defaults to `true`): Determines whether the + application stays running in the background even after a `[pause](../../../cordova/events/events.pause.html)` + event fires. Setting this to `false` does not kill the app after a + `[pause](../../../cordova/events/events.pause.html)` event, but simply halts execution of code within the cordova + webview while the app is in the background. + + <preference name="KeepRunning" value="false"/> + +- `LoadUrlTimeoutValue` (number in milliseconds, default to `20000`, + 20 seconds): When loading a page, the amount of time to wait before throwing + a timeout error. This example specifies 10 seconds rather than 20: + + <preference name="LoadUrlTimeoutValue" value="10000"/> + +- `SplashScreen` (string, defaults to `splash`): The name of the file minus + its extension in the `res/drawable` directory. Various assets must share + this common name in various subdirectories. + + <preference name="SplashScreen" value="mySplash"/> + +- `SplashScreenDelay` (number in milliseconds, defaults to `3000`): The amount + of time the splash screen image displays. + + <preference name="SplashScreenDelay" value="10000"/> + +- `InAppBrowserStorageEnabled` (boolean, defaults to `true`): Controls + whether pages opened within an InAppBrowser can access the same + localStorage and WebSQL storage as pages opened with the default + browser. + + <preference name="InAppBrowserStorageEnabled" value="true"/> + +- `LoadingDialog` (string, defaults to `null`): If set, displays a dialog with + the specified title and message, and a spinner, when loading the first + page of an application. The title and message are separated by a comma + in this value string, and that comma is removed before the dialog is + displayed. + + <preference name="LoadingDialog" value="My Title,My Message"/> + +- `LoadingPageDialog` (string, defaults to `null`): The same as `LoadingDialog`, + but for loading every page after the first page in the application. + + <preference name="LoadingPageDialog" value="My Title,My Message"/> + +- `ErrorUrl` (URL, defaults to `null`): + If set, will display the referenced page upon an error in the application + instead of a dialog with the title "Application Error". + + <preference name="ErrorUrl" value="myErrorPage.html"/> + +- `ShowTitle` (boolean, defaults to `false`): Show the title at the top + of the screen. + + <preference name="ShowTitle" value="true"/> + +- `LogLevel` (string, defaults to `ERROR`): Sets the minimum log level + through which log messages from your application will be filtered. Valid + values are `ERROR`, `WARN`, `INFO`, `DEBUG`, and `VERBOSE`. + + <preference name="LogLevel" value="VERBOSE"/> + +- `SetFullscreen` (boolean, defaults to `false`): Same as the `Fullscreen` + parameter in the global configuration of this xml file. This Android-specific + element is deprecated in favor of the global `Fullscreen` element, and will + be removed in a future version. + +- `AndroidLaunchMode` (string, defaults to `singleTop`): Sets the Activity + `android:launchMode` attribute. This changes what happens when the app is + launched from app icon or intent and is already running. + Valid values are `standard`, `singleTop`, `singleTask`, `singleInstance`. + + <preference name="AndroidLaunchMode" value="singleTop"/> + +- `DefaultVolumeStream` (string, defaults to `default`, added in cordova-android 3.7.0): Sets which volume + the hardware volume buttons link to. By default this is "call" for phones + and "media" for tablets. Set this to "media" to have your app's volume + buttons always change the media volume. Note that when using Cordova's + media plugin, the volume buttons will dynamically change to controlling + the media volume when any Media objects are active. + +- `OverrideUserAgent` (string, not set by default): + If set, the value will replace the old UserAgent of webview. + It is helpful to identify the request from app/browser when requesting remote pages. + Use with caution, this may causes compitiable issue with web servers. + For most cases, use AppendUserAgent instead. + + <preference name="OverrideUserAgent" value="Mozilla/5.0 My Browser" /> + +- `AppendUserAgent` (string, not set by default): + If set, the value will append to the end of old UserAgent of webview. + When using with OverrideUserAgent, this value will be ignored. + + <preference name="AppendUserAgent" value="My Browser" /> + + http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/21c8e8f0/www/docs/en/6.x/guide/platforms/android/index.md ---------------------------------------------------------------------- diff --git a/www/docs/en/6.x/guide/platforms/android/index.md b/www/docs/en/6.x/guide/platforms/android/index.md new file mode 100644 index 0000000..4f97111 --- /dev/null +++ b/www/docs/en/6.x/guide/platforms/android/index.md @@ -0,0 +1,307 @@ +--- +license: > + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +title: Android Platform Guide +--- + +# Android Platform Guide + +This guide shows how to set up your SDK environment to deploy Cordova +apps for Android devices, and how to optionally use Android-centered +command-line tools in your development workflow. You need to install +the Android SDK regardless of whether you want to use these +platform-centered shell tools or cross-platform Cordova CLI for +development. For a comparison of the two development paths, see the +[Overview](../../overview/index.html). For details on the CLI, see [The Command-Line Interface](../../cli/index.html). + +## Requirements and Support + +Cordova for Android requires the Android SDK which could be installed +on OS X, Linux or Windows operation system. See the Android SDK's +[System Requirements](http://developer.android.com/sdk/index.html#Requirements). + +Cordova supports Android 4.0.x (starting with Android API level 14) +and higher. As a general rule, Android versions become unsupported by Cordova as +they dip below 5% on Google's +[distribution dashboard](http://developer.android.com/about/dashboards/index.html). +Android versions earlier than API level 10, and the 3.x versions (Honeycomb, +API levels 11-13) fall significantly below that 5% threshold. + +## Install Cordova Shell Tools + +If you want to use Cordova's Android-centered shell tools in +conjunction with the SDK, download Cordova from +[cordova.apache.org](http://cordova.apache.org). Otherwise ignore this +section if you plan to use the cross-platform CLI tool described in +[The Command-Line Interface](../../cli/index.html). + +The Cordova download contains separate archives for each platform. Be +sure to expand the appropriate archive, `android` in this case, within +an empty directory. The relevant executible utilities are available +in the top-level `bin` directory. (Consult the __README__ file if +necessary for more detailed directions.) + +These shell tools allow you to create, build, and run Android apps. +For information on the additional command-line interface that enables +plugin features across all platforms, see Using Plugman to Manage +Plugins. See Application Plugins for details on how to develop +plugins. + +## Install the Java Development Kit (JDK) + +Install [Java Development Kit (JDK) 7](http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html) +or later. + +When installing on Windows you also need to set `JAVA_HOME` Environment Variable +according to JDK installation path (for example, C:\Program Files\Java\jdk1.7.0_75). + +## Install the Android SDK + +Install the [Android Stand-alone SDK Tools](http://developer.android.com/sdk/installing/index.html?pkg=tools) or [Android Studio](http://developer.android.com/sdk/installing/index.html?pkg=studio). Procceed with `Android Studio` if you plan +developing new Cordova for Android plugins or using native tools to +run and debug Android platform. Otherwise, `Android Stand-alone SDK Tools` +are enough to build and deploy Android application. + +Detailed installation instructions are available as part of installation +links above. + +For Cordova command-line tools to work, or the CLI that is based upon +them, you need to include the SDK's `tools` and `platform-tools` +directories in your `PATH`. On a Mac or Linux, you can 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: + + export PATH=${PATH}:/Development/android-sdk/platform-tools:/Development/android-sdk/tools + +This line in `~/.bash_profile` exposes these tools in newly opened terminal +windows. If your terminal window is already open in OSX, or to avoid a logout/login +on Linux, run this to make them available in the current terminal window: + + $ source ~/.bash_profile + +To modify the `PATH` environment on Windows: + +1. Click on the __Start__ menu in the lower-left corner of the desktop, + right-click on __Computer__, then select __Properties__. + +1. Select __Advanced System Settings__ in the column on the left. + +1. In the resulting dialog box, press __Environment Variables__. + +1. Select the __PATH__ variable and press __Edit__. + +1. Append the following to the `PATH` based on where you installed the + SDK, for example: + + ;C:\Development\android-sdk\platform-tools;C:\Development\android-sdk\tools + +1. Save the value and close both dialog boxes. + +## Install SDK Packages + +Open Android SDK Manager (for example, via terminal: `android`) and install: + +1. Android 5.1.1 (API 22) platform SDK +1. Android SDK Build-tools version 19.1.0 or higher +1. Android Support Repository (Extras) + +See [Installing SDK Packages](http://developer.android.com/sdk/installing/adding-packages.html) +for more details. + +## Configure an Emulator + +Android sdk doesn't provide any default emulator instance by default. You can +create a new one by running `android` on the command line. +The press __Tools → Manage AVDs__ (Android Virtual Devices), +then choose any item from __Device Definitions__ in the resulting dialog +box: + +![]({{ site.baseurl }}/static/img/guide/platforms/android/asdk_device.png) + +Press __Create AVD__, optionally modifying the name, then press __OK__ +to accept the changes: + +![]({{ site.baseurl }}/static/img/guide/platforms/android/asdk_newAVD.png) + +The AVD then appears in the __Android Virtual Devices__ list: + +![]({{ site.baseurl }}/static/img/guide/platforms/android/asdk_avds.png) + +To open the emulator as a separate application, select the AVD and +press __Start__. It launches much as it would on the device, with +additional controls available for hardware buttons: + +![]({{ site.baseurl }}/static/img/guide/platforms/android/asdk_emulator.png) + + +For a faster experience, you can use the `Virtual Machine Acceleration` to improve +the execution speed. +Many modern CPUs provide extensions to execute Virtual Machines more efficiently. +Before attempting to use this type of acceleration, you need to determine if your +current development system's CPU, supports one the following virtualization technologies: + +* __Intel Virtualization Technology__ (VT-x, vmx) → [Intel VT-x supported processor list](http://ark.intel.com/products/virtualizationtechnology) +* __AMD Virtualization__ (AMD-V, SVM), only supported for Linux (Since May 2006, all CPUs AMD include AMD-V, except Sempron). + +Another way to find out if your Intel processor supports VT-x Technology, it's by executing the +`Intel Processor Identification Utility`, for `Windows`you can download it from the Intel [Download Center](https://downloadcenter.intel.com/Detail_Desc.aspx?ProductID=1881&DwnldID=7838), +or you can use the [booteable utility](https://downloadcenter.intel.com/Detail_Desc.aspx?ProductID=1881&DwnldID=7840&lang=eng), which is `OS Independent`. + +After install and execute the `Intel Processor Identification Utility` over Windows, you will get the following window, +in order to check if your CPU supports the Virtualization Technologies: + +![]({{ site.baseurl }}/static/img/guide/platforms/android/intel_pid_util_620px.png) + +In order to speed up the emulator, you need to download and install one or more `Intel x86 Atom` System Images, +as well as the `Intel Hardware Accelerated Execution Manager (HAXM)`. + +Open your Android SDK Manager, and select the `Intel x86 Atom` System Image, for whichever version that you want to test. Then go to `Extras` +and select `Intel x86 Emulator Accelerator (HAXM)`, and install those packages: + +![]({{ site.baseurl }}/static/img/guide/platforms/android/asdk_man_intel_image_haxm.png) + +After download, run the Intel installer, which is available within your +Android SDK at `extras/intel/Hardware_Accelerated_Execution_Manager`. +__Note__:`If you have any problems installing the package, you can find more information and step by step guidance check this` +[Intel Article](http://software.intel.com/en-us/android/articles/speeding-up-the-android-emulator-on-intel-architecture). + +1. Install one or more `Intel x86 Atom` System Images as well as the + `Intel Hardware Accelerated Execution Manager`, available under + __Extras__. + +1. Run the Intel installer, which is available within your Android SDK + at `extras/intel/Hardware_Accelerated_Execution_Manager`. + +1. Create a new AVD with the target set to an Intel image. + +1. When starting the emulator, ensure there are no error messages + indicating a failure to load HAX modules. + +## Create a New Project + +At this point, to create a new project you can choose between the +cross-platform CLI tool described in [The Command-Line Interface](../../cli/index.html), or +the set of Android-specific shell tools. From within a source-code +directory, here's the CLI approach: + + $ cordova create hello com.example.hello HelloWorld + $ cd hello + $ cordova platform add android + $ ccordova prepare # or "cordova build" + +Here's the corresponding lower-level shell-tool approach for both Unix +and Windows: + + $ /path/to/cordova-android/bin/create /path/to/new/hello com.example.hello HelloWorld + C:\path\to\cordova-android\bin\create.bat C:\path\to\new\hello com.example.hello HelloWorld + +## Build the Project + +If you are using the CLI in development, the project directory's +top-level `www` directory contains the source files. Run any of +these within the project directory to rebuild the app: + + $ cordova build # build all platforms that were added + $ cordova build android # build debug for only Android + $ cordova build android --debug # build debug for only Android + $ cordova build android --release # build release for only Android + +If you are using the Android-specific shell tools in development, +there is a different approach. Once you generate the project, the +default app's source is available in the `assets/www` subdirectory. +Subsequent commands are available in its `cordova` subdirectory. + +The `build` command cleans project files and rebuilds the app. Here is +the syntax for both Mac and Windows. The first pair of examples +generate debugging information, and the second builds the apps for +release: + + $ /path/to/project/cordova/build --debug + C:\path\to\project\cordova\build.bat --debug + + $ /path/to/project/cordova/build --release + C:\path\to\project\cordova\build.bat --release + +## Deploy the app + +You can use the `cordova` CLI utility to deploy the +application to the emulator or the device from the command line: + + $ cordova emulate android #to deploy the app on a default android emulator + $ cordova run android --device #to deploy the app on a connected device + +Otherwise, use the alternate shell interface: + + $ /path/to/project/cordova/run --emulator + $ /path/to/project/cordova/run --device + +You can use __cordova run android --list__ to see all available targets and +__cordova run android --target=target_name__ to run application on a specific +device or emulator (for example, `cordova run android --target="Nexus4_emulator"`). + +You can also use __cordova run --help__ to see additional build and run +options. + +This pushes the app to the home screen and launches it: + +![]({{ site.baseurl }}/static/img/guide/platforms/android/emulator2x.png) + +When you `run` the app, you also `build` it. You can append additional +`--debug`, `--release`, and `--nobuild` flags to control how it is +built, or even whether a rebuild is necessary: + + $ /path/to/project/cordova/run --emulator --nobuild + +## Other Commands + +The following generates a detailed log of the app as it runs: + + $ /path/to/project/cordova/log + C:\path\to\project\cordova\log.bat + +The following cleans the project files: + + $ /path/to/project/cordova/clean + C:\path\to\project\cordova\clean.bat + +## Open a New Project in the SDK + +Once android platform is added to your project, you can open it from +within [Android Studio](http://developer.android.com/sdk/installing/index.html?pkg=studio): + +1. Launch the __Android Studio__ application. + +1. Select __Import Project (Eclipse ADT, Gradle, etc)__. + + ![]({{ site.baseurl }}/static/img/guide/platforms/android/asdk_import_project.png) + +1. Select location where android platform is stored (`your/project/platforms/android`). + + ![]({{ site.baseurl }}/static/img/guide/platforms/android/asdk_import_select_location.png) + +1. For the `Gradle Sync` question you can simply answer __Yes__. + +You are all set now and can build and run the app directly from `Android Studio`. + +![]({{ site.baseurl }}/static/img/guide/platforms/android/asdk_import_done.png) + +See [Android Studio Overview](http://developer.android.com/tools/studio/index.html) and +And [Building and Running from Android Studio](http://developer.android.com/tools/building/building-studio.html) for more details. + + --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org