linux版本:centos 6.5
提前准备好http proxy:
1.http_proxy=http://x.x.x.x:58989
2.备选的http proxy: sdk.gdgshanghai.com 8000
先安装node.js,需要pyhton 2.6以上
# cat /etc/system-release
CentOS release 6.5 (Final)
# locale
LANG=en_US.UTF-8
# wget https://nodejs.org/dist/v0.12.7/node-v0.12.7.tar.gz
# tar zxvf node-v0.12.7.tar.gz
# cd node-v0.12.7
# ./configure --prefix=/usr
# make
# make install
安装完毕
# npm --version
2.11.3
/////////////////////////////////////
开始npm,如果npm安装出现错误或者超时等等,可能需要挂http proxy,或者安装cnpm使用国内镜像站
使用http proxy方法命令后加 --proxy http://server:port 即可
安装cnpm的方法:
npm install -g cnpm --registry=https://registry.npm.taobao.org
之后就用cnpm代替 npm即可
另外,目前都是用root直接操作,如果在别的发行版,需要管理员权限操作
sudo npm xxx xxx
/////////////////////////////////////
安装cordova
# npm install -g cordova
安装完毕
# cordova --version
5.2.0
安装ionic
# npm install -g ionic -d
# ionic --version
1.6.4
测试ionic,创建一个新的app,成功提示里有些有用的tips
#mkdir /home/ionic_dev/
#cd /home/ionic_dev/
# ionic start ioapp_app_sidemenu sidemenu
....
Your Ionic project is ready to go! Some quick tips:
* cd into your project: $ cd ioapp_app_sidemenu
* Setup this project to use Sass: ionic setup sass
* Develop in the browser with live reload: ionic serve
* Add a platform (ios or Android): ionic platform add ios [android]
Note: iOS development requires OS X currently
See the Android Platform Guide for full Android installation instructions:
https://cordova.apache.org/docs/en/edge/guide_platforms_android_index.md.html
* Build your app: ionic build <PLATFORM>
* Simulate your app: ionic emulate <PLATFORM>
* Run your app on a device: ionic run <PLATFORM>
* Package an app using Ionic package service: ionic package <MODE> <PLATFORM>
For more help use ionic --help or ionic docs
Visit the Ionic docs: http://ionicframework.com/docs
打开调试服务,在浏览器里预览app界面
进入app目录
#ionic serve --address IP_address --port port
比如:ionic serve --address 192.168.1.129 --port 8101
直接ionic serve只监听localhost:8100,个人在本机开发建议这个,如果要多人开发,多人预览,使用上面的命令
如果浏览器访问不了,考虑iptables端口是否开放,测试服务器建议将iptables关闭
为了实现修改程序,浏览器自动刷新,以及多个app同时实现调试需要多个端口,可以把防火墙关掉(只针对内网测试服务器)
# service iptables stop 停服务
# chkconfig iptables off 停开机自动启动
安装JDK1.7
# cd /opt/
下载
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz"
# tar xzf jdk-7u79-linux-x64.tar.gz
# cd /opt/jdk1.7.0_79/
安装,如果有其他安装版本,需要选中本次安装的版本
# alternatives --install /usr/bin/java java /opt/jdk1.7.0_79/bin/java 2
# alternatives --config java
# alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_79/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_79/bin/javac 2
# alternatives --set jar /opt/jdk1.7.0_79/bin/jar
# alternatives --set javac /opt/jdk1.7.0_79/bin/javac
安装成功
# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
配置环境变量,写入~/.bashrc or ~/.bash_profile.
# kongzong install jdk
export JAVA_HOME=/opt/jdk1.7.0_79
export JRE_HOME=/opt/jdk1.7.0_79/jre
export PATH=$PATH:/opt/jdk1.7.0_79/bin:/opt/jdk1.7.0_79/jre/bin
安装android sdk
wget http://dl.google.com/android/android-sdk_r24.3.4-linux.tgz
解压到/opt/android-sdk-linux/
配置环境变量,写入~/.bashrc or ~/.bash_profile.
# kongzong android sdk
export ANDROID_HOME=/opt/android-sdk-linux
export PATH=$PATH:/opt/android-sdk-linux/tools:/opt/android-sdk-linux/platform-tools
这个时候只有android sdk,要能编译出apk,要需要一系列的platform 和 tools
服务器没有gui环境,使用命令行进行安装
android程序在/opt/android-sdk-liunx/tools/下,如果配置了环境变量,则可以直接使用
这个命令可以列出一共有哪些可安装的包
# android list sdk -a --proxy-host x.x.x.x --proxy-port 58989
输出如下
/////////////////////////////////////////////
Packages available for installation or update: 107
1- Android SDK Tools, revision 24.3.4
2- Android SDK Platform-tools, revision 23
3- Android SDK Build-tools, revision 23
4- Android SDK Build-tools, revision 22.0.1
5- Android SDK Build-tools, revision 22 (Obsolete)
6- Android SDK Build-tools, revision 21.1.2
7- Android SDK Build-tools, revision 21.1.1 (Obsolete)
8- Android SDK Build-tools, revision 21.1 (Obsolete)
9- Android SDK Build-tools, revision 21.0.2 (Obsolete)
10- Android SDK Build-tools, revision 21.0.1 (Obsolete)
11- Android SDK Build-tools, revision 21 (Obsolete)
12- Android SDK Build-tools, revision 20
13- Android SDK Build-tools, revision 19.1
14- Android SDK Build-tools, revision 19.0.3 (Obsolete)
15- Android SDK Build-tools, revision 19.0.2 (Obsolete)
16- Android SDK Build-tools, revision 19.0.1 (Obsolete)
17- Android SDK Build-tools, revision 19 (Obsolete)
18- Android SDK Build-tools, revision 18.1.1 (Obsolete)
19- Android SDK Build-tools, revision 18.1 (Obsolete)
20- Android SDK Build-tools, revision 18.0.1 (Obsolete)
21- Android SDK Build-tools, revision 17 (Obsolete)
22- Documentation for Android SDK, API 23, revision 1
23- Documentation for Android SDK, API 22, revision 1
24- SDK Platform Android 6.0, API 23, revision 1
25- SDK Platform Android 5.1.1, API 22, revision 2
26- SDK Platform Android 5.0.1, API 21, revision 2
27- SDK Platform Android 4.4W.2, API 20, revision 2
28- SDK Platform Android 4.4.2, API 19, revision 4
29- SDK Platform Android 4.3.1, API 18, revision 3
30- SDK Platform Android 4.2.2, API 17, revision 3
31- SDK Platform Android 4.1.2, API 16, revision 5
32- SDK Platform Android 4.0.3, API 15, revision 5
33- SDK Platform Android 4.0, API 14, revision 4 (Obsolete)
34- SDK Platform Android 3.2, API 13, revision 1 (Obsolete)
35- SDK Platform Android 3.1, API 12, revision 3 (Obsolete)
36- SDK Platform Android 3.0, API 11, revision 2 (Obsolete)
37- SDK Platform Android 2.3.3, API 10, revision 2
38- SDK Platform Android 2.3.1, API 9, revision 2 (Obsolete)
39- SDK Platform Android 2.2, API 8, revision 3
40- SDK Platform Android 2.1, API 7, revision 3 (Obsolete)
41- SDK Platform Android 2.0.1, API 6, revision 1 (Obsolete)
42- SDK Platform Android 2.0, API 5, revision 1 (Obsolete)
43- SDK Platform Android 1.6, API 4, revision 3 (Obsolete)
44- SDK Platform Android 1.5, API 3, revision 4 (Obsolete)
45- SDK Platform Android 1.1, API 2, revision 1 (Obsolete)
46- Samples for SDK API 23, revision 2
47- Samples for SDK API 22, revision 6
48- Samples for SDK API 21, revision 4
49- Samples for SDK API 20, revision 3
50- Samples for SDK API 19, revision 6
51- Samples for SDK API 18, revision 1
52- Samples for SDK API 17, revision 1
53- Samples for SDK API 16, revision 1
54- Samples for SDK API 15, revision 2
55- Samples for SDK API 14, revision 2 (Obsolete)
56- Samples for SDK API 13, revision 1 (Obsolete)
57- Samples for SDK API 12, revision 1 (Obsolete)
58- Samples for SDK API 11, revision 1 (Obsolete)
59- Samples for SDK API 10, revision 1
60- Samples for SDK API 9, revision 1 (Obsolete)
61- Samples for SDK API 8, revision 1
62- Samples for SDK API 7, revision 1 (Obsolete)
63- Google APIs, Android API 23, revision 1
64- Google APIs, Android API 22, revision 1
65- Google APIs, Android API 21, revision 1
66- Google APIs (ARM System Image), Android API 19, revision 15
67- Google APIs, Android API 18, revision 4
68- Google APIs, Android API 17, revision 4
69- Google APIs, Android API 16, revision 4
70- Google APIs, Android API 15, revision 3
71- Google APIs, Android API 14, revision 2 (Obsolete)
72- Google APIs, Android API 13, revision 1 (Obsolete)
73- Google TV Addon, Android API 13, revision 1 (Obsolete)
74- Google APIs, Android API 12, revision 1 (Obsolete)
75- Google TV Addon, Android API 12, revision 2 (Obsolete)
76- Google APIs, Android API 11, revision 1 (Obsolete)
77- Google APIs, Android API 10, revision 2
78- Google APIs, Android API 9, revision 2 (Obsolete)
79- Google APIs, Android API 8, revision 2
80- Google APIs, Android API 7, revision 1 (Obsolete)
81- Google APIs, Android API 6, revision 1 (Obsolete)
82- Google APIs, Android API 5, revision 1 (Obsolete)
83- Google APIs, Android API 4, revision 2 (Obsolete)
84- Google APIs, Android API 3, revision 3 (Obsolete)
85- Sources for Android SDK, API 23, revision 1
86- Sources for Android SDK, API 22, revision 1
87- Sources for Android SDK, API 21, revision 1
88- Sources for Android SDK, API 20, revision 1
89- Sources for Android SDK, API 19, revision 2
90- Sources for Android SDK, API 18, revision 1
91- Sources for Android SDK, API 17, revision 1
92- Sources for Android SDK, API 16, revision 2
93- Sources for Android SDK, API 15, revision 2
94- Sources for Android SDK, API 14, revision 1 (Obsolete)
95- Android Support Repository, revision 17
96- Android Support Library, revision 23
97- Google AdMob Ads SDK, revision 11 (Obsolete)
98- Google Analytics App Tracking SDK, revision 3 (Obsolete)
99- Google Cloud Messaging for Android Library, revision 3 (Obsolete)
100- Google Play services for Froyo, revision 12 (Obsolete)
101- Google Play services, revision 26
102- Google Repository, revision 20
103- Google Play APK Expansion Library, revision 3
104- Google Play Billing Library, revision 5
105- Google Play Licensing Library, revision 2
106- Android Auto API Simulators, revision 1
107- Google Web Driver, revision 2
/////////////////////////////////////////////
前面的数字就是下面命令中 -t 可以使用的packages number
这个命令安装全部可用包,因为使用了proxy,返回大量的400错误
# android update sdk --proxy-host x.x.x.x --proxy-port 58989 -u
这个命令可以定制安装个别包 -t packages number,packages number可以用上面的android list sdk获得
# android update sdk --proxy-host mirrors.opencas.cn --proxy-port 80 -u -a -t 2,3,4
最终成功运行的命令如下 -u是在命令行模式使用,-s是禁用https(使用proxy时避免400错误),可以加-t 过滤packages number
这里是安装全部可用包,预警,需要的空间很大,大概20g
# android update sdk --proxy-host x.x.x.x --proxy-port 58989 -u -s
这个命令需要暴快的proxy,或者墙外,不然就要等上一个晚上了,
其实用 -t 安装最新的Platform-tools,Build-tools就能达到可编译apk
我这次安装的全部内容如下
///////////////////////////////////////////////
Installing Archives:
Preparing to install archives
Downloading Android SDK Platform-tools, revision 23
Installing Android SDK Platform-tools, revision 23
Stopping ADB server failed (code -1).
Installed Android SDK Platform-tools, revision 2399%)
Downloading Android SDK Build-tools, revision 23
Installing Android SDK Build-tools, revision 23
Installed Android SDK Build-tools, revision 2399%)
Downloading Documentation for Android SDK, API 23, revision 1
Installing Documentation for Android SDK, API 23, revision 1
Installed Documentation for Android SDK, API 23, revision 199%)
Downloading SDK Platform Android 6.0, API 23, revision 1
Installing SDK Platform Android 6.0, API 23, revision 1
Installed SDK Platform Android 6.0, API 23, revision 197%)
Downloading SDK Platform Android 5.1.1, API 22, revision 2
Installing SDK Platform Android 5.1.1, API 22, revision 2
Installed SDK Platform Android 5.1.1, API 22, revision 296%)
Downloading SDK Platform Android 5.0.1, API 21, revision 2
Installing SDK Platform Android 5.0.1, API 21, revision 2
Installed SDK Platform Android 5.0.1, API 21, revision 296%)
Downloading SDK Platform Android 4.4W.2, API 20, revision 2
Installing SDK Platform Android 4.4W.2, API 20, revision 2
Installed SDK Platform Android 4.4W.2, API 20, revision 297%)
Downloading SDK Platform Android 4.4.2, API 19, revision 4
Installing SDK Platform Android 4.4.2, API 19, revision 4
Installed SDK Platform Android 4.4.2, API 19, revision 497%)
Downloading SDK Platform Android 4.3.1, API 18, revision 3
Installing SDK Platform Android 4.3.1, API 18, revision 3
Installed SDK Platform Android 4.3.1, API 18, revision 397%)
Downloading SDK Platform Android 4.2.2, API 17, revision 3
Installing SDK Platform Android 4.2.2, API 17, revision 3
Installed SDK Platform Android 4.2.2, API 17, revision 397%)
Downloading SDK Platform Android 4.1.2, API 16, revision 5
Installing SDK Platform Android 4.1.2, API 16, revision 5
Installed SDK Platform Android 4.1.2, API 16, revision 596%)
Downloading SDK Platform Android 4.0.3, API 15, revision 5
Installing SDK Platform Android 4.0.3, API 15, revision 5
Installed SDK Platform Android 4.0.3, API 15, revision 596%)
Downloading SDK Platform Android 2.3.3, API 10, revision 2
Installing SDK Platform Android 2.3.3, API 10, revision 2
Installed SDK Platform Android 2.3.3, API 10, revision 298%)
Downloading SDK Platform Android 2.2, API 8, revision 3
Installing SDK Platform Android 2.2, API 8, revision 3
Installed SDK Platform Android 2.2, API 8, revision 399%)
Downloading Samples for SDK API 23, revision 2
Installing Samples for SDK API 23, revision 2
Installed Samples for SDK API 23, revision 297%)
Downloading Samples for SDK API 22, revision 6
Installing Samples for SDK API 22, revision 6
Installed Samples for SDK API 22, revision 697%)
Downloading Samples for SDK API 21, revision 4
Installing Samples for SDK API 21, revision 4
Installed Samples for SDK API 21, revision 496%)
Downloading Samples for SDK API 20, revision 3
Installing Samples for SDK API 20, revision 3
Installed Samples for SDK API 20, revision 395%)
Downloading Samples for SDK API 19, revision 6
Installing Samples for SDK API 19, revision 6
Installed Samples for SDK API 19, revision 694%)
Downloading Samples for SDK API 18, revision 1
Installing Samples for SDK API 18, revision 1
Installed Samples for SDK API 18, revision 195%)
Downloading Samples for SDK API 17, revision 1
Installing Samples for SDK API 17, revision 1
Installed Samples for SDK API 17, revision 195%)
Downloading Samples for SDK API 16, revision 1
Installing Samples for SDK API 16, revision 1
Installed Samples for SDK API 16, revision 196%)
Downloading Samples for SDK API 15, revision 2
Installing Samples for SDK API 15, revision 2
Installed Samples for SDK API 15, revision 296%)
Downloading Samples for SDK API 10, revision 1
Installing Samples for SDK API 10, revision 1
Installed Samples for SDK API 10, revision 195%)
Downloading Samples for SDK API 8, revision 1
Installing Samples for SDK API 8, revision 1
Installed Samples for SDK API 8, revision 196%)
Downloading Android Support Repository, revision 17
Installing Android Support Repository, revision 17
Installed Android Support Repository, revision 1799%)
Downloading Android Support Library, revision 23
Installing Android Support Library, revision 23
Installed Android Support Library, revision 2393%)
Downloading Google Play services, revision 26
Installing Google Play services, revision 26
Installed Google Play services, revision 2697%)
Downloading Google Repository, revision 20
Installing Google Repository, revision 20
Installed Google Repository, revision 2099%)
Downloading Google Play APK Expansion Library, revision 3
Installing Google Play APK Expansion Library, revision 3
Installed Google Play APK Expansion Library, revision 378%)
Downloading Google Play Billing Library, revision 5
Installing Google Play Billing Library, revision 5
Installed Google Play Billing Library, revision 596%)
Downloading Google Play Licensing Library, revision 2
Installing Google Play Licensing Library, revision 2
Installed Google Play Licensing Library, revision 272%)
Downloading Android Auto API Simulators, revision 1
Installing Android Auto API Simulators, revision 1
Installed Android Auto API Simulators, revision 199%)
Downloading Google Web Driver, revision 2
Installing Google Web Driver, revision 2
Installed Google Web Driver, revision 299%)
Downloading Google APIs, Android API 23, revision 1
Installing Google APIs, Android API 23, revision 1
Installed Google APIs, Android API 23, revision 189%)
Downloading Google APIs, Android API 22, revision 1
Installing Google APIs, Android API 22, revision 1
Installed Google APIs, Android API 22, revision 189%)
Downloading Google APIs, Android API 21, revision 1
Installing Google APIs, Android API 21, revision 1
Installed Google APIs, Android API 21, revision 189%)
Downloading Google APIs (x86 System Image), Android API 19, revision 15
Installing Google APIs (x86 System Image), Android API 19, revision 15
Installed Google APIs (x86 System Image), Android API 19, revision 1599%)
Downloading Google APIs (ARM System Image), Android API 19, revision 15
Installing Google APIs (ARM System Image), Android API 19, revision 15
Installed Google APIs (ARM System Image), Android API 19, revision 1599%)
Downloading Glass Development Kit Preview, Android API 19, revision 11
Installing Glass Development Kit Preview, Android API 19, revision 11
Installed Glass Development Kit Preview, Android API 19, revision 1181%)
Downloading Google APIs, Android API 18, revision 4
Installing Google APIs, Android API 18, revision 4
Installed Google APIs, Android API 18, revision 499%)
Downloading Google APIs, Android API 17, revision 4
Installing Google APIs, Android API 17, revision 4
Installed Google APIs, Android API 17, revision 499%)
Downloading Google APIs, Android API 16, revision 4
Installing Google APIs, Android API 16, revision 4
Installed Google APIs, Android API 16, revision 499%)
Downloading Google APIs, Android API 15, revision 3
Installing Google APIs, Android API 15, revision 3
Installed Google APIs, Android API 15, revision 399%)
Downloading Google APIs, Android API 10, revision 2
Installing Google APIs, Android API 10, revision 2
Installed Google APIs, Android API 10, revision 299%)
Downloading Google APIs, Android API 8, revision 2
Installing Google APIs, Android API 8, revision 2
Installed Google APIs, Android API 8, revision 299%)
Downloading Google APIs ARM EABI v7a System Image, Google Inc. API 23, revision 7
Installing Google APIs ARM EABI v7a System Image, Google Inc. API 23, revision 7
Installed Google APIs ARM EABI v7a System Image, Google Inc. API 23, revision 799%)
Downloading Google APIs Intel x86 Atom_64 System Image, Google Inc. API 23, revision 7
Installing Google APIs Intel x86 Atom_64 System Image, Google Inc. API 23, revision 7
Installed Google APIs Intel x86 Atom_64 System Image, Google Inc. API 23, revision 799%)
Downloading Google APIs Intel x86 Atom System Image, Google Inc. API 23, revision 7
Installing Google APIs Intel x86 Atom System Image, Google Inc. API 23, revision 7
Installed Google APIs Intel x86 Atom System Image, Google Inc. API 23, revision 799%)
Downloading Google APIs ARM EABI v7a System Image, Google Inc. API 22, revision 1
Installing Google APIs ARM EABI v7a System Image, Google Inc. API 22, revision 1
Installed Google APIs ARM EABI v7a System Image, Google Inc. API 22, revision 199%)
Downloading Google APIs Intel x86 Atom_64 System Image, Google Inc. API 22, revision 1
Installing Google APIs Intel x86 Atom_64 System Image, Google Inc. API 22, revision 1
Installed Google APIs Intel x86 Atom_64 System Image, Google Inc. API 22, revision 199%)
Downloading Google APIs Intel x86 Atom System Image, Google Inc. API 22, revision 1
Installing Google APIs Intel x86 Atom System Image, Google Inc. API 22, revision 1
Installed Google APIs Intel x86 Atom System Image, Google Inc. API 22, revision 199%)
Downloading Google APIs ARM EABI v7a System Image, Google Inc. API 21, revision 7
Installing Google APIs ARM EABI v7a System Image, Google Inc. API 21, revision 7
Installed Google APIs ARM EABI v7a System Image, Google Inc. API 21, revision 799%)
Downloading Google APIs Intel x86 Atom_64 System Image, Google Inc. API 21, revision 7
Installing Google APIs Intel x86 Atom_64 System Image, Google Inc. API 21, revision 7
Installed Google APIs Intel x86 Atom_64 System Image, Google Inc. API 21, revision 799%)
Downloading Google APIs Intel x86 Atom System Image, Google Inc. API 21, revision 7
Installing Google APIs Intel x86 Atom System Image, Google Inc. API 21, revision 7
Installed Google APIs Intel x86 Atom System Image, Google Inc. API 21, revision 799%)
Updated ADB to support the USB devices declared in the SDK add-ons.
Stopping ADB server succeeded.
Starting ADB server succeeded.
Done. 55 packages installed.
////////////////////////////////////////////////
这一段是网上查到的如何命令行安装升级android sdk的原文:
///////////////////////////////////////////////
By default, the SDK Manager from the command line does not include the build tools in the list. They're in the "obsolete" category. To see all available downloads available, use
android list sdk --all
And then to get one of the packages in that list from the command line, use:
android update sdk -u -a -t <package no.>
Where -u stands for --no-ui, -a stands for --all and -t stands for --filter.
If you need to install multiple packages do:
android update sdk -u -a -t 1,2,3,4,..,n
Where 1,2,..,n is the package number listed with the list command above
////////////////////////////////////////////////
现在可以试试是否编译成功
# cd /home/ionic_dev/app_xxxx
# ionic build android
第一次会下载很多的依赖包
下载完后提示编译错误: ..........libgcc_s.so.1 can not open ...
解决方法如下,需要安装x86平台的一些编译工具,因为andriod sdk目前是x86的
#yum install -y glibc.i686 zlib.i686
本来可以一同安装libgcc.i686,但是往往这个包会提示libgcc.i686多个版本禁止安装,则要先运行
#yum update libgcc
然后
#yum install libgcc.i686
应该差不多了
继续ionic build android
依然有错误........q.js............
google了很久无果,想到有文章提过ionic build有错误,可以换成
cordova build android
成功了!!!
在/home/ionic_dev/ioapp_app_sidemenu/platforms/android/build/outputs/apk 下生成android-debug.apk
之后尝试ionic build android,还有若干次失败,但是也有成功,无解,估计是ionic的bug,但是cordova build每次都成功