/OkBuck

OkBuck is a gradle plugin, aiming to help developers utilize the fast build system: Buck, based on an existing project built using gradle. This plugin lets you have both build systems work side by side.

Primary LanguageGroovyMIT LicenseMIT

OkBuck

Download Master branch build status Android Arsenal

OkBuck is a gradle plugin, aiming to help developers utilize the fast build system: Buck, based on an existing project built using gradle. This plugin lets you have both build systems work side by side.

Wiki, 中文版

Why?

Gradle is typically the default build tool for android development, and to migrate to buck, there is a lot of overhead, which can be difficult and buggy. OkBuck automates this migration with very few lines of configuration.

Installation

In root project build.gradle file:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.github.okbuilds:okbuild-gradle-plugin:0.5.3'
    }
}

apply plugin: 'com.github.okbuilds.okbuck-gradle-plugin'

That's all for basic case, no need for any other configuration. After appling the plugin, these tasks are added

  • okbuck will generate BUCK files
  • okbuckClean will delete all files/dirs generated by OkBuck and BUCK
  • buckWrapper will create a buck wrapper script to invoke buck commands

You can type ./buckw targets to get a list of targets that can be build. The generated .buckconfig.local file will have some aliases setup to build your apps without having to type the rulename. i.e you can do things like ./buckw build appDebug another-appPaidRelease etc. The plugin also generates an empty .buckconfig file if it does not exist. You can customize the settings in the .buckconfig file by using the various options

Configuration

okbuck {
    buildToolVersion "23.0.3"
    target "android-23"
    linearAllocHardLimit = [
            app: 7194304
    ]
    primaryDexPatterns = [
            app: [
                    '^com/github/okbuilds/okbuck/example/AppShell^',
                    '^com/github/okbuilds/okbuck/example/BuildConfig^',
                    '^android/support/multidex/',
                    '^com/facebook/buck/android/support/exopackage/',
                    '^com/github/promeg/xlog_android/lib/XLogConfig^',
                    '^com/squareup/leakcanary/LeakCanary^',
            ]
    ]
    exopackage = [
            appDebug: true
    ]
    annotationProcessors = [
            "local-apt-dependency": ['com.okuilds.apt.ExampleProcessor']
    ]
    appLibDependencies = [
            'appProd': [
                    'buck-android-support',
                    'com.android.support:multidex',
                    'libraries/javalibrary:main',
                    'libraries/common:paidRelease',
            ],
            'appDev': [
                    'buck-android-support',
                    'com.android.support:multidex',
                    'libraries/javalibrary:main',
                    'libraries/common:freeDebug',
            ],
            'appDemo': [
                    'buck-android-support',
                    'com.android.support:multidex',
                    'libraries/javalibrary:main',
                    'libraries/common:paidRelease',
            ]
    ]
    buckProjects = project.subprojects

    wrapper {
        repo = 'https://github.com/OkBuilds/buck.git'
        remove = ['.buckconfig.local', "**/BUCK"]
        keep = [".okbuck/**/BUCK"]
    }
}
  • buildToolVersion specifies the version of the Android SDK Build-tools, defaults to 23.0.3
  • target specifies the Android compile sdk version, default is android-23
  • linearAllocHardLimit and primaryDexPatterns are maps, configuration used by buck for multidex. For more details about multidex configuration, please read the Multidex wiki page, if you don't need multidex, you can ignore these parameters
  • exopackage, appClassSource and appLibDependencies are used for configuring buck's exopackage mode. For more details about exopackage configuration, please read the Exopackage wiki page, if you don't need exopackage, you can ignore these parameters
  • annotationProcessors is used to depend on annotation processors declared locally as another gradle module in the same root project.
  • buckProjects is a set of projects to generate buck configs for. Default is all sub projects of the root project.
  • wrapper is used to create a buck wrapper script that downloads and installs buck. It can detect when to automatically run the okbuck task before invoking buck commands. To install the wrapper, you need to run the buckWrapper task and can invoke buck commands via the buckw wrapper script.
  • repo - The git url of any custom buck fork. Default is OkBuilds/buck
  • remove - List of file patterns to clean up by wrapper before running okbuck. Defaults to ['.buckconfig.local', '**/BUCK']
  • keep - List of file patterns to not clean up by the wrapper before running okbuck. This may be useful if you want made manual modifications to some buck configuration and would like to keep it intact while regenerating the configuration for other projects. By default it is set to ['.okbuck/**/BUCK'].
  • The keys used to configure various options can be either for
  • All buildTypes and flavors i.e app
  • All buildTypes of a particular flavor i.e 'appDemo'
  • All flavors of a particular buildType i.e 'appDebug'
  • A particular variant (buildType + flavor combination) i,e 'appDemoRelease'

Common Issues

  • If you use ndk filters in your build.grade, you must set the ANDROID_NDK environment variable pointing to your local android ndk root dir, otherwise BUCK build will fail.
  • If your project uses gradle 2.4, youneed force jdk version to 1.7, ref1 and ref2
  • OkBuck aims to provide almost all the features that the android gradle plugin provides,but your project may still be incompatible with buck for various reasons listed on the Known caveats wiki page.

Compatibility

OkBuck is tested under gradle 2.2.1 ~ 2.13, and com.android.tools.build:gradle 1.5.0 ~ 2.1.0. If other versions have any compatibility problems, please file an issue.

Liscense

The MIT License (MIT)

Copyright (c) 2015 OkBuilds

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.