One of the Cordova3.x series is environment setup and Common commands, one of the cordova3.x series.

Source: Internet
Author: User

One of the Cordova3.x series is environment setup and Common commands, one of the cordova3.x series.

Solemnly declare that the knowledge points involved in this series of blog articles are obtained from others' blogs, which are summarized by hands-on practices. Many operation details are omitted to consolidate what they have learned, in the future, we will launch a series of blog posts on Cordova.

 

I. Some knowledge about Cordova
Mobile apps fall into three categories: Native apps, Hybrid apps, and Web apps. Among them, Hybrid App is between Native App and Web App. It can take into account the good user experience and powerful functions of Native App, and has the advantage of cross-platform and rapid development of Web apps. The disadvantage is that it depends on the WebView of various platforms. The performance of WebView directly determines the performance of Hybrid App. Hybrid App development frameworks at home and abroad are quite a lot at present, representing Cordova (aka PhoneGap) outside China) sencha Touch, Titanium, Intel XDK, RhoMobile, Xamarin, and domestic AppCan, Rexsee, xFace, and Dr. phoneGap and Titanium won the Jolt Productivity Award in the 2014 mobile development tool Jolt award issued by Dobb's Journal. Titanium should belong to Converter from Web to Native, and also has Native JavaScript applications, such as Chrome Apps/Firefox OS/Windows 8 apps. Based on the open-source Cordova, major companies have launched their own products, such as Adobe PhoneGap, Oracle ADF Mobile, SAP Kapsel, IBM Worklight, and Microsoft Visual Studio.
2. Preparations for Environment setup
1. JDK development environment and environment variable configuration check command: java-version 2. Android SDK development environment and environment variable configuration check command: android-h 3, Ant download and installation, and environment variable configuration check command: ant-version 4, Nodejs download and installation, and environment variable configuration check command: node-v npm-v 5, Git download and installation, and environment variable configuration check command: git -- version 6, Cordova CLI installation and environment variable configuration check command: npm install-g cordova (install cordova)
3. Create a project to run a series of operations
1. Create the root directory of the project and enter the directory cd e: \ proroot at the command prompt. (files generated or downloaded through various commands will be stored in this directory in the future)
2. create a project firstdemo command: cordova create firstdemo com. test. the firstdemo MyDemo project folder is firstdemo and the package name is com. test. firstdemo, the project name is MyDemo (MyDemo is the project name imported to the eclipse project later)
3. Go to the project directory firstdemo and add platform support. The operation command is as follows: cordova platforms add ios cordova platforms add android display platform LIST command: cordova platforms ls
4. add the required development plug-ins to the project. The operation command is as follows: The cordova plugin add Command requires the developer to specify the repository for the plug-in code. The list of commonly used plug-ins is as follows:
(1) Basic device information API cordova plugin add org. apache. cordova. device
(2) network connection and battery events cordova plugin add org. apache. cordova. network-information cordova plugin add org. apache. cordova. battery-status
(3) Acceleration pointer, compass, and geographic location cordova plugin add org. apache. cordova. device-motion cordova plugin add org. apache. cordova. device-orientation cordova plugin add org. apache. cordova. geolocation
(4) camera, media replay and capture cordova plugin add org. apache. cordova. camera cordova plugin add org. apache. cordova. media-capture cordova plugin add org. apache. cordova. media
(5) access the file cordova plugin add org. apache. cordova. file cordova plugin add org. apache. cordova. file-transfer on the device or network.
(6) Notify cordova plugin add org. apache. cordova. dialogs cordova plugin add org. apache. cordova. vibration through the dialog box or vibration
(7) Contact cordova plugin add org. apache. cordova. contacts
(8) Internationalized cordova plugin add org. apache. cordova. globalization (9) flash screen (startup animation) cordova plugin add org. apache. cordova. splashscreen
(10) open the new browser window cordova plugin add org. apache. cordova. inappbrowser
(11) debugging console cordova plugin add org. apache. cordova. console
 5. compile the project code cordova build android
6. run the Project (1) run on the simulator: cordova emulate android (create a virtual machine first) (2) run cordova run android on the real machine through USB (3) run: cordova serve android on the browser
Note: after each change to the project, you must run the compilation command and running command to see the latest results. Iv. Common commands
(1) create <directory> [<id> [name] to create a cordova project. The id is the package name.
(2) platform [ls | list] lists the platforms supported by the project
(3) platform add <platform> [<platform>...] add one or more platforms for the project
(4) platform [rm | remove] <platform> [<platform>...] delete a platform support for this project
(5) platform [up | update] <platform> updates the Cordova version of a platform of this project.
(6) plugin [ls | list] lists the plug-ins contained in the project.
(7) plugin add <path-to-plugin> [path-to-plugin...] add one or more plug-ins for the project (8) plugin [rm | remove] <plugin-name> [plugin-name...] delete a plug-in from this project
(9) plugin search [<keyword1> <keyword2>...] search plug-ins from registry for the root keyword
(10) compile [platform...] compile the app package of the specified platform
(11) build [<platform> [<platform>] [...] First prepare (copy file) and then compile
(12) emulate [<platform> [<platform>] [...] Start the simulator to run the application
(13) serve [port] Start the Local web service to access www. The default port is 8080.
V. Introduction to Cordova files1. config. xml cordova configuration file
2. The hooks directory stores the script file of the custom cordova command. Each project command can define before and after hooks, such as before_build and after_build. Hook can be written in any programming language. Cordova CLI uses Node. js, so it is generally used for writing.
3. The merges directory stores special files on various platforms and will be combined and compiled with www. files under the same file merges are preferred. Compile and use
4. Do not manually modify the native code project of each platform in the platforms directory, because it will be overwritten during build.
5. plugins directory plug-in directory (native APIs provided by cordova are also provided in the form of plug-ins) 6. www directory source code directory, in cordova prepare, it will be copied to the assets \ www directory of each platform project. In this example, index.html is the entry file of the application.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.