

Designed by Freepik

We all have been using Gradle since Google switched to it as official Android build system, but it’s not the fastest one. Today we’re going to look at Buck by Facebook, a way faster build system. Instead of minutes you build in seconds.

Buck

Although faster, it’s not as simple in setup, you can check this page for official doccumentation, that’s why we’re goint to use a Gradle Plugin by Uber – OkBuck

OkBuck

Using Gradle Plugin is way simpler and you won’t need to change entire build code and learn new syntax. To enable it add those lines to your project’s build.gradle

buildscript { repositories { jcenter() } dependencies { classpath 'com.uber:okbuck:0.19.0' } } repositories { jcenter() } apply plugin: 'com.uber.okbuck' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 buildscript { repositories { jcenter ( ) } dependencies { classpath 'com.uber:okbuck:0.19.0' } } repositories { jcenter ( ) } apply plugin : 'com.uber.okbuck'

Then run those commands if you’re on Mac

brew update # Required to build and use buck brew install android-ndk ant # Optional, but recommended for faster development brew install watchman 1 2 3 4 5 6 7 brew update # Required to build and use buck brew install android - ndk ant # Optional , but recommended for faster development brew install watchman

or those if you’re using Linux

$ git clone https://github.com/facebook/watchman.git $ cd watchman/ $ git checkout v4.7.0 $ sudo apt-get install -y autoconf automake build-essential python-dev $ ./autogen.sh $ ./configure $ make $ sudo make install $ watchman --version $ echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_user_watches && echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_queued_events && echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_user_instances && watchman shutdown-server 1 2 3 4 5 6 7 8 9 10 11 $ git clone https : //github.com/facebook/watchman.git $ cd watchman / $ git checkout v4 . 7.0 $ sudo apt - get install - y autoconf automake build - essential python - dev $ . / autogen . sh $ . / configure $ make $ sudo make install $ watchman -- version $ echo 999999 | sudo tee - a / proc / sys / fs / inotify / max_user_watches && echo 999999 | sudo tee - a / proc / sys / fs / inotify / max_queued_events && echo 999999 | sudo tee - a / proc / sys / fs / inotify / max_user_instances && watchman shutdown - server

Then run this command from your project

./gradlew :buckWrapper 1 . / gradlew : buckWrapper

Build

To see list of possible build use

./buckw targets 1 . / buckw targets

If you don’t have any flavors, then run

./buckw build //app:bin_debug 1 . / buckw build / / app : bin_debug

Otherwise bin_flavorDebug.

Signing

It will complain that you didn’t set release signing, add those lines to your build.gradle

signingConfigs { debug { storeFile "${System.properties['user.home']}${File.separator}.android${File.separator}debug.keystore" as File storePassword 'android' keyAlias 'androiddebugkey' keyPassword 'android' } } buildTypes { debug { signingConfig signingConfigs.debug } release { minifyEnabled false signingConfig signingConfigs.debug proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 signingConfigs { debug { storeFile "${System.properties['user.home']}${File.separator}.android${File.separator}debug.keystore" as File storePassword 'android' keyAlias 'androiddebugkey' keyPassword 'android' } } buildTypes { debug { signingConfig signingConfigs . debug } release { minifyEnabled false signingConfig signingConfigs . debug proguardFiles getDefaultProguardFile ( 'proguard-android.txt' ) , 'proguard-rules.pro' } }

And retry build command.

Release signing

As you see we use the same config for both debug and release builds, that’s ok for development so that it doesn’t compain. If you decide to stick with OkBuck, then you do the following, otherwise you can skip this part. Set release congif by putting those lines to local.properties file. This is the same debug config, replace it with your release when ready. Since this file is in git ingored by default you’re not risking to share it with anybody

storeFile=/home/ihor/.android/debug.keystore storePassword=android keyAlias=androiddebugkey keyPassword=android 1 2 3 4 storeFile = / home / ihor / . android / debug . keystore storePassword = android keyAlias = androiddebugkey keyPassword = android

replace storeFile with your path to release or debug keystore for now. And change release config to this

Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) signingConfigs { release { storeFile properties.getProperty('storeFile') as File storePassword properties.getProperty('storePassword') keyAlias properties.getProperty('keyAlias') keyPassword properties.getProperty('keypass') } } 1 2 3 4 5 6 7 8 9 10 11 Properties properties = new Properties ( ) properties . load ( project . rootProject . file ( 'local.properties' ) . newDataInputStream ( ) ) signingConfigs { release { storeFile properties . getProperty ( 'storeFile' ) as File storePassword properties . getProperty ( 'storePassword' ) keyAlias properties . getProperty ( 'keyAlias' ) keyPassword properties . getProperty ( 'keypass' ) } }

Apply it in buildTypes for release build

Install

Finally, let’s install and run our app

./buckw install --run //app:bin_debug 1 . / buckw install -- run / / app : bin_debug

Limitations

Ok, so Buck more perfomant than Gradle, but there’s some limitations with Android yet. Most discouraging is not supported Data Binding and Kotlin, but they will come later. If you don’t use Kotlin, you can stick with Butterknife instead of Data Binding, which is supported, and try yourself if it’s faster to build with Buck.

Yes, Gradle runs great when you have an empty project and just started your IDE, what really matters is the middle of the day, that’s when it’s slow as never. So try it out, I’ve just recently discovered Buck, will write my review later

Alrgiht, that’s it for Buck build system so far, you can check source code here. Don’t forget to subscribe, follow me on Twitter, Facebook, G+ and share with friends if you think they will benefit from it!