1.安装nodejs
nodejs官网: https://nodejs.org/
下载地址:https://nodejs.org/download/
win7 64位操作系统下载:node-v0.12.2-x64.msi
下载后直接安装即可。
进入cmd:
C:\Users\Administrator>node -v
v0.12.2
C:\Users\Administrator>npm -v
2.7.4
安装成功。
2.安装git客户端
下载地址: http://git-scm.com/download/win
下载后的文件名:Git-1.9.5-preview20150319.exe
直接安装即可。
进入cmd 执行命令:
C:\Users\Administrator>git --version
git version 1.9.5.msysgit.1
如果指示:'git' 不是内部或外部命令
把git命令所在目录(C:\Program Files (x86)\Git\bin\) 加入PATH环境变量就好了。
3.安装 android_sdk
下载Android SDK Tools,在baidu搜吧,如:installer_r24.0.2-windows.exe
安装时指定目录(Android sdk 存放目录),安装完成后,打开SDK Manager,弹出窗口:
这个工具用来在线下载 Android sdk,默认是去官网下载,但国内目前访问不了google ,所以需要配置代理:点击tools菜单->options:
如上图配置代理,(或baidu其它代理)--》close。
Packages菜单->reoad ,如果代理好用的话,就会显示可以安装包了。
选择最新版本的Android sdk ,点击 Install package。
安装完成后,配置环境变量:
ANDROID_HOME: Android sdk 存放目录
在PATH环境变量中增加:%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;
4.安装ANT
http://ant.apache.org/ 下载ant ,存入指定目录解压
配置环境变量:ANT_HOME=解压目录
在PATH环境变量中增加:%ANT_HOME%\bin
5.安装cordova
在 cmd 中执行:
npm install -g cordova
C:\Users\Administrator>npm install -g cordova npm WARN engine [email protected]: wanted: {"node":">=0.6","npm":"1"} (current: {"node": "0.12.2","npm":"2.7.4"}) npm WARN engine [email protected]: wanted: {"node":"~0.10.x"} (current: {"node":" 0.12.2","npm":"2.7.4"}) npm WARN engine [email protected]: wanted: {"node":"0.8.x || 0.10.x"} (current: { "node":"0.12.2","npm":"2.7.4"}) npm WARN installMany normalize-package-data was bundled with [email protected], but bund led package wasn't found in unpacked tree C:\Users\Administrator\AppData\Roaming\npm\cordova -> C:\Users\Administrator\App Data\Roaming\npm\node_modules\cordova\bin\cordova [email protected] C:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova ├── [email protected] ├── [email protected] ├── [email protected] ([email protected]) └── [email protected] ([email protected], [email protected], properties-parser @0.2.3, [email protected], [email protected], [email protected], [email protected], [email protected] .0, [email protected], [email protected], [email protected], [email protected], [email protected], elem [email protected], [email protected], [email protected], [email protected], [email protected] .3, [email protected], [email protected], [email protected], [email protected] .0, [email protected], [email protected])
6创建项目:
cordova create 目录名 包名 项目名
如:
C:\Users\Administrator>cordova create TestApp com.temp TestApp Creating a new cordova project.
这时当前目录下有一个TestApp目录,进入目录: cd TestApp 添加Android 平台:
C:\Users\Administrator>cd TestApp C:\Users\Administrator\TestApp>cordova platform add android npm http GET https://registry.npmjs.org/cordova-android/4.0.0 npm http 304 https://registry.npmjs.org/cordova-android/4.0.0 Adding android project... Creating Cordova project for the Android platform: Path: platforms\android Package: com.temp Name: TestApp Activity: MainActivity Android target: android-22 Copying template files... Android project created with [email protected] Discovered plugin "cordova-plugin-whitelist" in config.xml. Installing oject Fetching plugin "cordova-plugin-whitelist@1" via npm npm http GET https://registry.npmjs.org/cordova-plugin-whitelist npm http 304 https://registry.npmjs.org/cordova-plugin-whitelist Installing "cordova-plugin-whitelist" for android
项目打包并在手机上运行:(前提是通过usb连接手机,电脑上已装手机驱动,手机开启USB调试)
C:\Users\Administrator\TestApp>cordova run android Running command: C:\Users\Administrator\TestApp\platforms\android\cordova\run.ba t ANDROID_HOME=E:\Android\android-sdk JAVA_HOME=E:\Java\jdk1.7.0_60 WARNING : No target specified, deploying to device '89UKPBUCEMHE5H5D'. Running: C:\Users\Administrator\TestApp\platforms\android\gradlew cdvBuildDebug -b C:\Users\Administrator\TestApp\platforms\android\build.gradle -PcdvBuildArch= arm -Dorg.gradle.daemon=true :preBuild :compileDebugNdk :preDebugBuild :checkDebugManifest :CordovaLib:compileLint :CordovaLib:copyDebugLint UP-TO-DATE :CordovaLib:mergeDebugProguardFiles :CordovaLib:preBuild :CordovaLib:preDebugBuild :CordovaLib:checkDebugManifest :CordovaLib:prepareDebugDependencies :CordovaLib:compileDebugAidl :CordovaLib:compileDebugRenderscript :CordovaLib:generateDebugBuildConfig :CordovaLib:generateDebugAssets UP-TO-DATE :CordovaLib:mergeDebugAssets :CordovaLib:generateDebugResValues :CordovaLib:generateDebugResources :CordovaLib:packageDebugResources :CordovaLib:processDebugManifest :CordovaLib:processDebugResources :CordovaLib:generateDebugSources :CordovaLib:compileDebugJava 注: 某些输入文件使用或覆盖了已过时的 API。 注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。 :CordovaLib:processDebugJavaRes UP-TO-DATE :CordovaLib:packageDebugJar :CordovaLib:compileDebugNdk :CordovaLib:packageDebugJniLibs UP-TO-DATE :CordovaLib:packageDebugLocalJar UP-TO-DATE :CordovaLib:packageDebugRenderscript UP-TO-DATE :CordovaLib:bundleDebug :prepareAndroidCordovaLibUnspecifiedDebugLibrary :prepareDebugDependencies :compileDebugAidl :compileDebugRenderscript :generateDebugBuildConfig :generateDebugAssets UP-TO-DATE :mergeDebugAssets :generateDebugResValues :generateDebugResources :mergeDebugResources :processDebugManifest :processDebugResources :generateDebugSources :compileDebugJava :preDexDebug :dexDebug :processDebugJavaRes UP-TO-DATE :validateDebugSigning :packageDebug :zipalignDebug :assembleDebug :cdvBuildDebug BUILD SUCCESSFUL Total time: 28.311 secs Built the following apk(s): C:\Users\Administrator\TestApp\platforms\android\build\outputs\apk\android-d ebug.apk Using apk: C:\Users\Administrator\TestApp\platforms\android\build\outputs\apk\an droid-debug.apk Installing app on device... Launching application... LAUNCH SUCCESS
这样程序就安装到手机上了。
项目下有个www目录,保存了前端页面 index.html及相关的css及js。