記錄自己在安裝配置buck過程中出現(xiàn)的bug霹俺,寫本文的主要目的是放了方便記錄,如果文中哪些技術(shù)使用不當(dāng),希望能改指出;
**
Buck環(huán)境配置
**
有兩種方式可以下載Buck,一種是通過brew(這個(gè)通過apt-get install brew )安裝模聋,但是由于中國(guó)網(wǎng)絡(luò)的原因,我并沒有安裝成功唠亚,所以我使用了第二種方式链方,通過源碼安裝;
需要下載buck和Watchman源碼
克隆buck源碼
git clone https://github.com/facebook/buck.git
克隆watchman源碼,F(xiàn)acebook 開源的一個(gè)文件監(jiān)控服務(wù)灶搜,用來監(jiān)視文件并且記錄文件的改動(dòng)情況祟蚀,當(dāng)文件變更它可以觸發(fā)一些操作,例如執(zhí)行一些命令等等占调。安裝watchman暂题,是為了避免Buck每次都去解析 build files移剪,同時(shí)可以緩存其他一些東西究珊,減少編譯時(shí)間。
git clone https://github.com/facebook/watchman.git
下載速度相當(dāng)之坑爹纵苛,由于下載這個(gè)源碼的原因剿涮,耽誤了我將近一天的時(shí)間;
有需要的同學(xué)可以去我的網(wǎng)盤中下載日期是2016/08/09 (這可是情人節(jié)啊,為了下載這個(gè)都沒過好) 網(wǎng)盤地址[buck]:http://yunpan.cn/c6bZ2hD5bXKfD (提取碼:71c6)和[watchman]: http://yunpan.cn/c6bZ6GxEjcwvi (提取碼:68a5);
在下載源碼的同時(shí)可以先將編譯源碼所需要的環(huán)境配置好;
//編譯watchman所需要
sudo apt-get install automake
Oracle JDK 7
Apache Ant 1.8 (or newer)
Python 2.6 or 2.7
Git
C 編譯器:gcc或者clang
Android SDK
Android NDK(r10e)
JDK,Android SDK 配置配置查看 我之前寫的一片文章http://www.reibang.com/p/9c035cdc1899
安裝NDK
Android NDK 這個(gè)一定要使用r10e攻人,我之前使用的r11b但是由于在編譯buck的過程中沒有成功取试,提示沒有arm-linux-androideabi-4.8,后來使用r10e怀吻,編譯通過;
下載NDK后由于是bin格式瞬浓,所以直接安裝即可,安裝之前不要忘記給權(quán)限蓬坡,我的安裝地址是/opt/Android/NDK/android-ndk-r10e猿棉,安裝成功之后配置環(huán)境變量;
首先sudo gedit /etc/profile將環(huán)境變量添加到最后;
export NDK_HOME=/opt/Android/NDK/android-ndk-r10e
export PATH=$NDK_HOME:$PATH
安裝 ANT
下載Apache Ant 1.8 (or newer) http://ant.apache.org/,我使用的是最新版屑咳,apache-ant-1.9.7萨赁,解壓到/opt/apache-ant-1.9.7
之后配置環(huán)境變量
export ANT_HOME=/opt/apache-ant-1.9.7
export PATH=$ANT_HOME/bin:$PATH
通過ant -version 查看是否安裝成功
安裝GIT
sudo apt-get install git
安裝python
sudo apt-get install python-dev
通過輸入 python查看安裝版本,由于我之前使用的是ubuntu自帶的python兆龙,在編譯watchman的時(shí)候提示杖爽,沒有python.h 文件;忘記錯(cuò)誤是什么了,反正是重新安裝了一下最新的python之后沒有問題了,
GCC
這個(gè)ubuntu里面自帶慰安,這里不再贅述了;
buck和watchman的源碼終于下完了;
開始編譯watchman
進(jìn)入到watchman的目錄之后
$ cd watchman
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install
在經(jīng)歷各種問題之后終于安裝成功了;watchman -v 查看版本 我的是4.7.0
開始編譯buck
$ cd buck
$ ant
$ ./bin/buck --help
在編譯過程中出現(xiàn)過由于NDK 版本不對(duì)導(dǎo)致編譯失敗腋寨,還有就是由于源碼下載不完整導(dǎo)致編譯失敗;
以后會(huì)頻繁使用到buck安裝目錄下面的bin/buck命令,所以為了方便在Terminal中直接執(zhí)行buck命令化焕,需要將該目錄添加到環(huán)境變量中精置,cd到用戶主目錄,打開.bash_profile文件:
sudo gedit /etc/profile
添加如下配置:
export PATH=/home/jiangcy/software/buck-master/bin:$PATH
接著執(zhí)行如下命令使該配置立即生效:
source /etc/profile
快速創(chuàng)建基于 Buck 構(gòu)建的 Android 工程
使用命令可以快速創(chuàng)建一個(gè)Android工程锣杂,該命令執(zhí)行過程中會(huì)要求你補(bǔ)全如下兩個(gè)參數(shù)的值:
touch .buckconfig && buck quickstart
Enter the directory where you would like to create the project: BuckTest
Thanks for installing Buck!
In this quickstart project, the file apps/myapp/BUCK defines the build rules.
At this point, you should move into the project directory and try running:
buck build //apps/myapp:app
or:
buck build app
See .buckconfig for a full list of aliases.
If you have an Android device connected to your computer, you can also try:
buck install app
This information is located in the file README.md if you need to access it
later.
進(jìn)入到工程根目錄脂倦,在Terminal中輸入如下命令創(chuàng)建IntelliJ工程:
buck project --ide IntelliJ
創(chuàng)建成功,顯示一下數(shù)據(jù)
jiangcy@jiangcy:~/jcybuck/BuckTest/BuckTest$ buck project --ide IntelliJ
Using watchman.
OK //java/com/example/activity:activity#dummy_r_dot_java BUILT_LOCALLY buck-out/gen/java/com/example/activity/__activity#dummy_r_dot_java_dummyrdotjava_output__/activity#dummy_r_dot_java.jar
[-] PROCESSING BUCK FILES...FINISHED 0.1s [100%] ?? New buck daemon
[-] GENERATING PROJECT...FINISHED 1.5s
[-] DOWNLOADING... (0.00 B/S AVG, TOTAL: 0.00 B, 0 Artifacts)
[-] BUILDING...FINISHED 0.7s [100%] (2/2 JOBS, 2 UPDATED, 2 [100.0%] CACHE MISS)
之后進(jìn)入工程目錄查看Readme中的的使用命令元莫,
Thanks for installing Buck!
In this quickstart project, the file apps/myapp/BUCK defines the build rules.
At this point, you should move into the project directory and try running:
buck build //apps/myapp:app
or:
buck build app
See .buckconfig for a full list of aliases.
If you have an Android device connected to your computer, you can also try:
buck install app
This information is located in the file README.md if you need to access it
later.
主要參考文獻(xiàn)
基于Facebook Buck改造Android構(gòu)建系統(tǒng)之初體驗(yàn)
使用buck構(gòu)建你的Android App