mac 搭建 ionic2 环境

2017-09-21  本文已影响0人  SevenLonely

1.安装Homebrew

homebrew 是一个mac下面的包管理工具我们可以通过它来安装一下开发上的东西。


/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

homebrew官方网站

2.安装java 环境

brew cask install java

查看java环境是否安装成功
java -version

成功的消息提示

3.安装node

node官方网站

直接去node官网上下载下来人后安装就行了,推荐使用稳定版。如果追求高版本的话可以下载测试版

查看是否安装成功执行node -v 查看node版本

:用brew 安装的node出现过在项目中下载一些包不能成功,项目启动不能成功!所以自己手动下载安装

4.安装ionic,cordova


npm install -g ionic cordova

查看是否安装成功

//查看ionic版本
ionic -v

//查看cordova 版本
cordova -v

5.创建项目

ionic start  项目名

创建完成项目然后启动查看下项目是否创建成功,如果启动成功后执行下一步

6.安装android-sdk(建议用方法二,简单快捷方便,管理也好用)


方法一

1.启动Terminal终端工具
2.输入cd ~/ 进入当前用户的home目录
3. 创建:touch .bash_profile
4.打开并编辑:open .bash_profile
5、在文件中写入以下内容:

exportANDROID_HOME=/usr/local/opt/android-sdk

export PATH=${PATH}:${ANDROID_HOME}/tools

export PATH=${PATH}:${ANDROID_HOME}/platform-tools

保存按Esc按钮输入

:wq    //保存退出

注:上面的目录根据你自己的sdk路径而改变

6、执行如下命令立即生效:source .bash_profile
7、验证:输入android回车。如果未显示command not found,说明此命令有效,环境变量设置完成。

方法二


brew cask install android-sdk

查看成功


android

安装android 编译tools

# 列出所有已安装、可安装、可更新的包
sdkmanager --list

结果如下(做了简化,仅供参考)

Installed packages:
  Path                              | Version | Description                       | Location
  -------                           | ------- | -------                           | -------
  add-ons;addon-g..._apis-google-22 | 1.0.0   | Google APIs, Android 22           | add-ons/addon-g...apis-google-22/
  build-tools;25.0.2                | 25.0.2  | Android SDK Build-Tools 25.0.2    | build-tools/25.0.2/
  docs                              | 1       | Documentation for Android SDK     | docs/
  emulator                          | 26.0.0  | Android Emulator                  | emulator/
  extras;android;m2repository       | 47.0.0  | Android Support Repository        | extras/android/m2repository/
  extras;google;m2repository        | 55      | Google Repository                 | extras/google/m2repository/
  extras;m2reposi...ut-solver;1.0.2 | 1       | Solver for ConstraintLayout 1.0.2 | extras/m2reposi...t-solver/1.0.2/
  extras;m2reposi...nt-layout;1.0.2 | 1       | ConstraintLayout for Android 1... | extras/m2reposi...t-layout/1.0.2/
  patcher;v1                        | 1       | SDK Patch Applier v1              | patcher/v1/
  patcher;v4                        | 1       | SDK Patch Applier v4              | patcher/v4/
  platform-tools                    | 25.0.5  | Android SDK Platform-Tools        | platform-tools/
  platforms;android-25              | 3       | Android SDK Platform 25, rev 3    | platforms/android-25/
  sources;android-25                | 1       | Sources for Android 25            | sources/android-25/
  system-images;a...gle_apis;x86_64 | 4       | Google APIs Intel x86 Atom_64 ... | system-images/a...le_apis/x86_64/
  tools                             | 26.0.2  | Android SDK Tools                 | tools/

Available Packages:
  Path                              | Version      | Description
  -------                           | -------      | -------
  add-ons;addon-g..._apis-google-24 | 1            | Google APIs
  add-ons;addon-g...e_gdk-google-19 | 11           | Glass Development Kit Preview
  build-tools;26.0.0                | 26.0.0       | Android SDK Build-Tools 26
  cmake;3.6.4111459                 | 3.6.4111459  | CMake 3.6.4111459
  docs                              | 1            | Documentation for Android SDK
  emulator                          | 26.0.3       | Android Emulator
  extras;android;gapid;1            | 1.0.3        | GPU Debugging tools
  extras;android;gapid;3            | 3.1.0        | GPU Debugging tools
  extras;android;m2repository       | 47.0.0       | Android Support Repository
  extras;google;auto                | 1.1          | Android Auto Desktop Head Unit...
  extras;google;g...e_play_services | 42           | Google Play services
  extras;google;instantapps         | 1.0.0        | Instant Apps Development SDK
  extras;google;m2repository        | 55           | Google Repository
  extras;google;m...t_apk_expansion | 1            | Google Play APK Expansion library
  extras;google;market_licensing    | 1            | Google Play Licensing Library
  extras;google;play_billing        | 5            | Google Play Billing Library
  extras;google;simulators          | 1            | Android Auto API Simulators
  extras;google;webdriver           | 2            | Google Web Driver
  extras;intel;Ha...ecution_Manager | 6.1.1        | Intel x86 Emulator Accelerator...
  extras;m2reposi...ut-solver;1.0.0 | 1            | Solver for ConstraintLayout 1.0.0
  extras;m2reposi...er;1.0.0-alpha4 | 1            | com.android.support.constraint...
  extras;m2reposi...ut-solver;1.0.2 | 1            | Solver for ConstraintLayout 1.0.2
  extras;m2reposi...nt-layout;1.0.0 | 1            | ConstraintLayout for Android 1...
  extras;m2reposi...out;1.0.0-beta5 | 1            | ConstraintLayout for Android 1...
  extras;m2reposi...nt-layout;1.0.2 | 1            | ConstraintLayout for Android 1...
  lldb;2.3                          | 2.3.3614996  | LLDB 2.3
  ndk-bundle                        | 15.1.4119039 | NDK
  patcher;v4                        | 1            | SDK Patch Applier v4
  platform-tools                    | 26.0.0       | Android SDK Platform-Tools
  platforms;android-26              | 1            | Android SDK Platform 26
  sources;android-25                | 1            | Sources for Android 25
  system-images;a...s_playstore;x86 | 4            | Google Play Intel x86 Atom Sys...
  tools                             | 26.0.2       | Android SDK Tools

Available Updates:
  ID                                          | Installed | Available
  -------                                     | -------   | -------
  emulator                                    | 26.0.0    | 26.0.3
  platform-tools                              | 25.0.5    | 26.0.0
  system-images;android-25;google_apis;x86_64 | 4         | 6
done

安装

sdkmanager "platforms;android-26"

sdkmanager "build-tools;26.0.0"

至此android sdk安装完成

7.安装gradle


brew install gradle

注意:gradle版本不正确安装指定gradle版本可查看brew安装指定版本gradle

8.打包


cordova platform add android

cordova build android


至此打包完成

上一篇下一篇

猜你喜欢

热点阅读