Gradle • Build automation tool, builds upon Maven and Ant • Uses build.gradle files for configuration ! PROTIP • Use the gradle wrapper http://www.gradle.org/
Module build file Main application build file. It would contain information such as dependencies, plugins, etc. With the Android plugin, you can define additional properties for your application, such as package name, version code, etc. Project ├── app │ ├── build.gradle │ ├── keystore │ ├── libs │ │ └── *.jar │ └── src └── build.gradle
Basic App Structure My build.gradle is configured to pick up all jars in this folder. Use this for dependencies not available via published repositories. ! compile fileTree(dir: 'libs', include: '*.jar') . ├── app │ ├── build.gradle │ ├── keystore │ ├── libs │ │ └── *.jar │ └── src └── build.gradle
Build Types Some added tasks: • assembleDebug • assembleRelease ! ./gradlew assembleRelease OR ./gradlew aR Each configuration creates some appropriate corresponding tasks.
Android Configuration This sample : • Defines minSdkVersion and maxSdkVersion • Defines package name • Defines version code and version name • Adds version name to BuildConfig (access it with BuildConfig.VERSION_MAJOR, no need for a Context!). Next version of the build tools will have more information out of the box, such as package name, version name, version code, etc.
Customizing Builds This sample : • Adds a suffix to the package name for debug build types • Adds a suffix to the version name for debug build types • Configures release build types to use a signing configuration that is shown in the next slide
Customizing Builds : Merging • All build types share code from the main source set • The manifest is merged into the app manifest • The code acts as just another source folder • The resources are overlayed over the main resources, replacing existing values
Customizing Builds : Uses • Permissions in debug mode only, but not in release mode • Custom implementation for debugging • Different resources for debug mode (for instance when a resource value is tied to the signing certificate)
sourceSets.beta.setRoot('src/release') This creates a custom build type named ‘beta’, initializing it from the properties of the release build type. By default, it would have it’s source set under ‘src/beta’. Here I manually set the source set to be under ‘src/ release’. The only difference between the two versions in my case is that beta has a suffix in it’s version name.
Signing packages This uses a file ‘keystore’ with an alias ‘keystore’. It asks for a password for both via the command line. Alternatively, you can make it pick up system properties, or pick them up in a file like signing.properties