Getting Started

Platform:iOSAndroidJavaOther
Development OS:macOSLinuxWindows

Unfortunately, Apple only lets you develop for iOS on a Mac.

This is a quick start guide for getting up and running with Buck. This article is light on details, instead focusing on the commands that you need to run to install Buck and build your first application from scratch using Buck.

While not a prerequisite for installing Buck itself, in order to build iOS applications, you will also need to install Xcode.

This is a quick start guide for getting up and running with Buck. This article is light on details, instead focusing on the commands that you need to run to install Buck.

While not a prerequisite for installing Buck itself, to build Android applications, you will also need at least the Android SDK, which can be installed via Chocolatey or manually downloaded and installed.

This is a quick start guide for getting up and running with Buck. This article is light on details, instead focusing on the commands that you need to run to install Buck.

This is a quick start guide for getting up and running with Buck. This article is light on details, instead focusing on the commands that you need to run to install Buck and build your first application from scratch using Buck.

While not a prerequisite for installing Buck itself, to build Android applications, you will also need at least the Android SDK, which can be installed via Homebrew or manually downloaded and installed.
While not a prerequisite for installing Buck itself, to build Android applications, you will also need at least the Android SDK, which can be installed via apt-get (or your distro's package manager) or manually downloaded and installed.

You can find a more detailed explanation about each step in the development process by reading the individual articles on more specific topics.

The commands in this guide are designed to be copy-pasteable, idempotent, and usable on its representative operating system (OS X, Windows, Linux). Sometimes this results in some unusual constructions (such as using echo instead of vi or emacs to create a file). Bear in mind that this is a quick start guide, so few things are quicker than copy-and-paste!

You can find a more detailed explanation about each step in the development process by reading the individual articles on more specific topics.

The commands in this guide are designed to be copy-pasteable, idempotent, and usable on its representative operating system (OS X, Windows, Linux). Sometimes this results in some unusual constructions (such as using echo instead of vi or emacs to create a file). Bear in mind that this is a quick start guide, so few things are quicker than copy-and-paste!

Currently, there is no way to download a precompiled binary for Buck.

Install with Homebrew

Buck is available as bottle on Homebrew.

Prerequisites

# Install command line tools. NOTE: If you have Xcode installed, these may
# already be installed.
xcode-select --install
# Install Java - this installs the JDK, a superset of the JRE
brew tap caskroom/cask
brew cask install java

If for some reason you do not have Xcode installed and you get an error error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist, then run xcode-select --reset to reset the command line tools path to where command line tools is installed.

Brew install

You have two choices when using Homebrew. You can choose to get the latest binary release:

brew tap facebook/fb
brew install buck

Or, you can get the latest and greatest code and build it locally.:

brew update
brew tap facebook/fb
brew install --HEAD buck

Build from Source

Prerequisites

To manually build Buck, download and install the following prerequisites:

With watchman, Buck will use a daemon which will prevent Buck from parsing all of your build files every time and cache some other things as well. It is strongly recommended that you install Watchman.

You can use Homebrew to install many of the prerequisites on a Mac.

# Install Command Line tools first. NOTE: If you have Xcode installed, these may
# already be installed.
xcode-select --install
# Then the JDK (superset of the JRE)
brew update
brew tap caskroom/cask
brew install java
# Then...
brew install ant python git watchman

If for some reason you do not have Xcode installed and you get an error error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist, then run xcode-select --reset to reset the command line tools path to where command line tools is installed.

Build

Once you have the above tools installed, you can install Buck as follows:

git clone https://github.com/facebook/buck.git
cd buck
ant
./bin/buck --help

If everything worked correctly, you should see something like:

buck build tool
usage:
  buck [options]
  buck command --help
  buck command [command-options]
available commands:
  audit       lists the inputs for the specified target
  build       builds the specified target
  cache       makes calls to the artifact cache
  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
  root        prints the absolute path to the root of the current buck project
  run         runs a target as a command
  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 APK
options:
 --help         : Shows this screen and exits.
 --version (-V) : Show version number.

Because you will likely be running ./bin/buck often, you should add it to your path so that you can simply run buck from the command line.

Build from Source

Prerequisites

To manually build Buck, download and install the following prerequisites:

With watchman, Buck will use a daemon which will prevent Buck from parsing all of your build files every time and cache some other things as well. It is strongly recommended that you install Watchman.

You can use Chocolatey to install many of the prerequisites on Windows.

choco install jdk8 ant python2 git
# install watchman as stated in the watchman prerequisite link above

You can use your distro's package manager (e.g., apt) to install many of the prerequisites on Linux. For example on Ubuntu 16.04, you can run the following:

sudo apt-get update
sudo apt-get install default-jdk ant python2 git
# install watchman as stated in the watchman prerequisite link above

For some distros, the default packages may be older than what you would like. In those cases, either build those packages from source, or find third party repositories beyond the default that is used by apt-get via sudo add-apt-repository (or however you add new repositories on your distro).

Environment Variables

You will need to tell Buck where to find our SDK and NDK. Buck will look at the value of the ANDROID_HOME environment variable to locate the SDK files on your system. Buck will look at ANDROID_NDK to find a specific version of the NDK, and ANDROID_NDK_REPOSITORY to find an appropriate NDK from a directory containing multiple NDK versions.

Build

Once you have the above tools installed, you can install Buck as follows:

git clone https://github.com/facebook/buck.git
cd buck
ant
.\bin\buck --help
git clone https://github.com/facebook/buck.git
cd buck
ant
./bin/buck --help

If everything worked correctly, you should see something like:

buck build tool
usage:
  buck [options]
  buck command --help
  buck command [command-options]
available commands:
  audit       lists the inputs for the specified target
  build       builds the specified target
  cache       makes calls to the artifact cache
  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
  root        prints the absolute path to the root of the current buck project
  run         runs a target as a command
  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 APK
options:
 --help         : Shows this screen and exits.
 --version (-V) : Show version number.

Because you will likely be running .\bin\buck often, you should add it to your path so that you can simply run buck from the command line.

Because you will likely be running ./bin/buck often, you should add it to your path so that you can simply run buck from the command line.

Trying Buck

Now that Buck is installed, it is time use Buck in a sample project.

Clone Buck Samples Repo

git clone git@github.com:fbsamples/bucksamples.git
cd bucksamples/cross-platform-scale-2015-demo/

Key iOS Files

This sample app has all the files necessary to use Buck to build an iOS project. From the root directory, you will find:

  • ios/main.m: The main iOS file supported by other views, controllers and associated resources.

  • ios/BUCK: The build file is what makes Buck work. It defines all the build rules for your source code. A build rule may also include dependencies (via deps), which may be from other build files.

  • .buckconfig: A .buckconfig file allows for various flag and alias settings for any project (even beyond iOS) within the root directory.

Build the iOS Sample

In order to build the app, you use the buck build command, specifying your app as the target. The target may be defined in the [alias] section in the .buckconfig file or it would be the name of your iOS project prepended by //[the directory where your project is located]: (e.g., //ios:BuckDempApp).

# From the root `cross-platform-scale-2015-demo/` directory
# demo_app_ios is an alias in .buckconfig for //ios::BuckDemoApp. Either works.
buck build demo_app_ios

You should see output similar to:

buck build demo_app_ios
[-] PROCESSING BUCK FILES...FINISHED 0.0s [100%]
[-] DOWNLOADING... (0.00 B/S AVG, TOTAL: 0.00 B, 0 Artifacts)
[-] BUILDING...FINISHED 0.7s [100%] (1/1 JOBS, 0 UPDATED, 0 [0.0%] CACHE MISS)

The first time you build, you will most likely see a longer time and cache misses. Subsequent builds should be much faster, with minimal cache misses.

Buck outputs its results in the buck-out/ directory.

Run the Built iOS App

Now that you know your app has built successfully, you can install and run the app with buck install. This command both compiles and installs the application on the iOS simulator. Using the --run flag will launch the simulator as well.

buck install --run demo_app_ios
Successfully launched demo_app_ios. To debug, run: lldb -p 50240
[-] PROCESSING BUCK FILES...FINISHED 0.0s [100%]
[-] DOWNLOADING... (0.00 B/S AVG, TOTAL: 0.00 B, 0 Artifacts)
[-] BUILDING...FINISHED 0.3s [100%] (1/1 JOBS, 0 UPDATED, 0 [0.0%] CACHE MISS)
[-] INSTALLING...FINISHED 38.7s

Success!

If all goes well, you should see something similar to:

iOS Hello Buck
::...
免责声明:
当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
内容版权归原作者所有;
本人对内容的有效性/合法性不承担任何强制性责任.
若有不妥, 欢迎评注提醒:

或是邮件反馈可也:
askdama[AT]googlegroups.com


订阅 substack 体验古早写作:


点击注册~> 获得 100$ 体验券: DigitalOcean Referral Badge

关注公众号, 持续获得相关各种嗯哼:
zoomquiet


自怼圈/年度番新

DU22.4
关于 ~ DebugUself with DAMA ;-)
粤ICP备18025058号-1
公安备案号: 44049002000656 ...::