ubuntu下搭建cordova开发环境

http://levi.cg.am/archives/3587(看这篇就够了)
不!
这篇写得更好:http://aguegu.net/?p=1822

Cyper实战:
将android加入环境变量
$ vi ~/.bashrc

#AndroidDev PATH
export PATH=${PATH}:~/android/android-sdk-linux/tools
export PATH=${PATH}:~/android/android-sdk-linux/platform-tools

$ source ~/.bashrc

1. Install Apache Cordova with npm

$ sudo npm install -g cordova
...
/usr/local/bin/cordova -> /usr/local/lib/node_modules/cordova/bin/cordova
cordova@4.0.0 /usr/local/lib/node_modules/cordova

2. Create a Cordova app and cd to the new folder
$ mkdir -p ~/cordova/projects/helloworld
$ cd ~/cordova/projects/helloworld 
$ cordova create hello com.example.hello "Hello World"
$ cd hello/

3. Add Android as a cordova platform
$ cordova platform add android
如果出现错误Error: Please install Android target "android-19".
则先输入android打开SDK Manager勾选Android4.4.2(API 19)下面的SDK Platform和ARM EABI v7a System Image)

Creating android project...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: com.example.hello
Name: Hello World
Android target: android-19
Copying template files...
Project successfully created.

$ sudo apt-get install ant
然后ant就装好了。which ant --> /usr/bin/ant --> /usr/share/bin/ant
(如果不安装ant执行接下来的cordova emulate或build命令会报错:
Failed to run "ant -version", make sure you have ant installed and added to your PATH.)

4. Create an Android emulator
$ android create avd -n hello -t 1
Auto-selecting single ABI armeabi-v7a
Android 4.4.2 is a basic Android platform.

(-n指定avd的名称,-t指定target level,可以通过android list targets来显示目前有哪些api level)

5. Run the cordova app on the emulator
$ cordova emulate android
半天没反应

$ emulator -avd hello或者emulator @hello
Segmentation fault (core dumped)

解决:http://blog.csdn.net/ritterliu/article/details/10949833
我是这么做的,先开个terminal执行emulator-arm @hello打开模拟器,
然后呢直接cordova run android

Build an APK package
cordova build
BUILD SUCCESSFUL
Total time: 28 seconds
Built the following apk(s):
    /home/cyper/cordova/projects/helloworld/hello/platforms/android/ant-build/CordovaApp-debug.apk



转载于:https://my.oschina.net/uniquejava/blog/333973

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值