一、安装Buck

Buck是一个由Facebook推出的开源Android build工具。Buck可以加速你的Android构建,它通过独立构件并行来发挥多核的性能。进一步的,它还可以通过跟踪不变资源的情况下减少增量构建次数,从而以最小的资源集重建。它采用特殊的构建步骤,与Ant构建脚本不同。Facebook称,Buck最关注的就是速度,Buck的速度是Ant的两倍。

1、环境

Buck当前只支持 Mac OS X 和 Linux
本文以Mac OS X平台为例进行介绍
首先需要确保你的 OS X 满足以下条件:

Oracle JDK 7
Apache Ant 1.8 (or newer)
Python 2.6 or 2.7
Git
C 编译器:gcc或者clang
Android SDK

上述环境都要加入环境变量里。


2、安装Buck


1) 在终端里执行如下命令:
git clone https://github.com/facebook/buck.git

如果下载不动的话,可以去 网盘里下载。 2) 加入环境变量
vim ~/.bash_profileexport PATH="/Users/liumeng/Documents/MySDK/buck-master/bin:$PATH" source ~/.bash_profile

3、安装 Watchman

Facebook 开源的一个文件监控服务,用来监视文件并且记录文件的改动情况,当文件变更它可以触发一些操作,例如执行一些命令等等。安装watchman,是为了避免Buck每次都去解析 build files,同时可以缓存其他一些东西,减少编译时间。Watchman安装很简单,脚本如下:
brew install watchman

4、验证

buck --help
如果一切正常的话,你会得到如下日志信息:
buck build toolusage:  buck [options]  buck command --help  buck command [command-options]available commands:  audit       lists the inputs for the specified target  build       builds the specified target  clean       deletes any generated files  fetch       downloads remote resources to your local machine  install     builds and installs an application  project     generates project configuration files for an IDE  query       provides facilities to query information about the target nodes graph  quickstart  generates a default project directory  server      query and control the http server  targets     prints the list of buildable targets  test        builds and runs the tests for the specified target  uninstall   uninstalls an APKoptions: --help         : Shows this screen and exits. --version (-V) : Show version number.


二、使用OkBuck 给Android Studio + Gradle 一键生成 buck 脚本


1、在现有工程的根目录下的 build.gradle 添加

buildscript {    repositories {        jcenter()    }    dependencies {        ...        classpath "com.github.piasy:okbuck-gradle-plugin:0.2.3"...    }}allprojects {    ...}apply plugin: 'com.github.piasy.okbuck-gradle-plugin'okbuck {    target "android-21"    overwrite true    signConfigName "release"    resPackages = [            'app'    : 'net.masonliu.app',            'library': 'net.masonliu.okhttpplus'    ]}

1) apply plugin 要放到 allprojects 下面;
2) overwrite指定是否覆盖已有的buck配置文件;
3) resPackages用于指定每个Android library module和Android application module的R文件的包名,你需要在resPackages里面为每个module指定包名,将dummylibrary/app替换为你的module的名字,引号里面的内容通常都是对应module的AndroidManifest.xml中的包名。
4) signConfigName是指

android {    ...    signingConfigs {        release {            ...        }    }    ...}

中的 signingConfig name

2、在工程根目录下的.gitignore里添加忽略配置


#buck.buckconfig*/BUCK.buckd.okbuckbuck-out

3、生成 buck 配置

./gradlew okbuck

4、编译

在工程根目录执行buck install app即可开始使用buck构建安装了(假设你的application module叫app)

buck install app

三、使用Buck for IDEA修改 生成后的 buck 文件

目前 Okbuck 生成的 buck 文件还有局限性,需要手动修改,可以使用此 插件 参考 buck文件 语法: http://zgssheng.cn/2014/03/facebook-buck%E7%BC%96%E8%AF%91apk%E5%8C%85/


更多相关文章

  1. 如何在首次启动时跳过Google安装向导
  2. Maven系列 8.Maven发布
  3. 移动端对html input标签文件选择支持
  4. android 条码识别软件开发全解析:1
  5. Android运行时异常“Binary XML file line # : Error inflating
  6. 【Android】利用表格布局,Android中xml文件与java的交互制作登录
  7. Android砖机救活(索爱MT15i)
  8. Xamarin.Android使用教程之简介和安装
  9. 转-Lottie开源动画库介绍与使用示例

随机推荐

  1. AndroidStudio Unknown attribute androi
  2. ProgressBar使用详解(进度条动画)
  3. 移动端H5的Video标签无法播放在线视频的
  4. AudioRecord||AudioTrack
  5. android scaleType的属性
  6. Android:Error retrieving parent for it
  7. Android:获取APK签名信息
  8. Android(安卓)activity属性设置大全
  9. Android控件属性大全
  10. Android(安卓)NDK开发之Android.mk文件