ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Reid Baker
Gradle + Android
What it is + How to get up to speed
01
What is Gradle?
? Build system!
? Language independent!
? Flexible dependency
management !
? Built on Groovy!
? Future of android development
Why should you use Gradle?
? Easy setup with Gradle wrapper !
? Make builds faster!
? Separate editor and compiler!
? More control over your builds!
? Control build tools versions!
? Change properties!
? Manage dependencies
GradleWrapper
? No installation of gradle is needed after setting up !
? Sets your version of gradle and where to look for it!
? Works for *NIX and Windows!
? ./gradlew tasks will list what you can do
Faster you say?
? Incremental builds!
? Avoid work you don¡¯t need easily ex. only lint debug
builds and proguard release builds!
? Set ?ags in settings.gradle to make gradle faster?
org.gradle.daemon=true
Freedom to update
? IDE updates can¡¯t break the build!
? Android tool updates can¡¯t break the build!
? install<buildtype> will assemble your apk and install it to the
connected device!
? Dependencies are stored locally in the build directory
It is all about control
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
}
}
apply plugin: ¡®android¡¯
!
repositories {
maven {
url ¡°https://maven.vpn.etonreve.com/repo¡±
}
}
!
//Where should I find the android tools
//What version of the android tools
!
//Tell gradle to we want to use the
android plugin
!
//Where are the android dependancies
located
Control over your apk
android {
compileSdkVersion 17
buildToolsVersion "19.0.1"
!
sourceSets.main {
java.srcDirs = ['src']
res.srcDirs = ['res']
manifest.srcFile ¡®AndroidManifest.xml¡¯
}
!
buildTypes {
debug {
debuggable true //unnecessary
packageNameSuffix '.dev'
if (someVariable) {
signingConfig signingConfigs.release
}
}
<Other release types>
}
}
Dependency management
dependencies {
compile project(¡°:libraries:skitchkit-android")
!
compile ¡®com.android.support:support-v4:19.0.+¡¯
!
compile ('com.actionbarsherlock:actionbarsherlock:4.4.0@aar') {
exclude group: 'com.android.support', module: 'support-v4'
}
!
compile files('/Users/rbaker/dev/google-play-services.jar')
!
provided 'com.google.android.maps:maps:16_r2'
}
BuildTypes and BuildFlavors
Release Types!
? Ex. Debug, Beta, Release!
? Change package!
? Change signing key
Build ?avors!
? Ex. Architecture, ?
Free/Premium?
Branding!
? Can be grouped !
? Can have different src
and res directories
Lets look at a real build file
Tips andTricks
? ./gradlew uninstall[flavor] will uninstall the previous version!
? Shorten commands with camel case ex.?
./gradlew installAllArchEvernoteDebug?
./gradlew iAAED!
!
!
? Handy command line arguments?
--offline??ag while building to not go to the server??
--refresh-dependencies?to tell Gradle to fetch all new dependencies?!
? Dependencies are cached for 24 hours but you can change how long?
configurations.all {?
resolutionStrategy.cacheDynamicVersionsFor 4, ¡®hours¡¯?
}!
!
? .aar??le is a zip. you can unzip it to see what¡¯s inside.!
!
? Install the groovy shell to quickly verify that your groovy does what it is supposed to!
Additional Resources
? Start by watching this Google IO talk:?http://
www.youtube.com/watch?v=LCJAgPkpmR0!
? Get up to speed with Groovy:?http://groovy.codehaus.org/
Groovy+style+and+language+feature+guidelines+for+Java
+developers!
? Get up to speed with Gradle:?http://fb?ex.wordpress.com/
2013/05/01/12-new-things-i-learned-from-a-three-day-
gradle-training/!
? More info about resource merging ?http://tools.android.com/
tech-docs/new-build-system/resource-merging
Thanks for coming
Follow me on twitter @reidbaker

More Related Content

Intro to Gradle + How to get up to speed

  • 1. Reid Baker Gradle + Android What it is + How to get up to speed
  • 2. 01 What is Gradle? ? Build system! ? Language independent! ? Flexible dependency management ! ? Built on Groovy! ? Future of android development
  • 3. Why should you use Gradle? ? Easy setup with Gradle wrapper ! ? Make builds faster! ? Separate editor and compiler! ? More control over your builds! ? Control build tools versions! ? Change properties! ? Manage dependencies
  • 4. GradleWrapper ? No installation of gradle is needed after setting up ! ? Sets your version of gradle and where to look for it! ? Works for *NIX and Windows! ? ./gradlew tasks will list what you can do
  • 5. Faster you say? ? Incremental builds! ? Avoid work you don¡¯t need easily ex. only lint debug builds and proguard release builds! ? Set ?ags in settings.gradle to make gradle faster? org.gradle.daemon=true
  • 6. Freedom to update ? IDE updates can¡¯t break the build! ? Android tool updates can¡¯t break the build! ? install<buildtype> will assemble your apk and install it to the connected device! ? Dependencies are stored locally in the build directory
  • 7. It is all about control buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.10.+' } } apply plugin: ¡®android¡¯ ! repositories { maven { url ¡°https://maven.vpn.etonreve.com/repo¡± } } ! //Where should I find the android tools //What version of the android tools ! //Tell gradle to we want to use the android plugin ! //Where are the android dependancies located
  • 8. Control over your apk android { compileSdkVersion 17 buildToolsVersion "19.0.1" ! sourceSets.main { java.srcDirs = ['src'] res.srcDirs = ['res'] manifest.srcFile ¡®AndroidManifest.xml¡¯ } ! buildTypes { debug { debuggable true //unnecessary packageNameSuffix '.dev' if (someVariable) { signingConfig signingConfigs.release } } <Other release types> } }
  • 9. Dependency management dependencies { compile project(¡°:libraries:skitchkit-android") ! compile ¡®com.android.support:support-v4:19.0.+¡¯ ! compile ('com.actionbarsherlock:actionbarsherlock:4.4.0@aar') { exclude group: 'com.android.support', module: 'support-v4' } ! compile files('/Users/rbaker/dev/google-play-services.jar') ! provided 'com.google.android.maps:maps:16_r2' }
  • 10. BuildTypes and BuildFlavors Release Types! ? Ex. Debug, Beta, Release! ? Change package! ? Change signing key Build ?avors! ? Ex. Architecture, ? Free/Premium? Branding! ? Can be grouped ! ? Can have different src and res directories
  • 11. Lets look at a real build file
  • 12. Tips andTricks ? ./gradlew uninstall[flavor] will uninstall the previous version! ? Shorten commands with camel case ex.? ./gradlew installAllArchEvernoteDebug? ./gradlew iAAED! ! ! ? Handy command line arguments? --offline??ag while building to not go to the server?? --refresh-dependencies?to tell Gradle to fetch all new dependencies?! ? Dependencies are cached for 24 hours but you can change how long? configurations.all {? resolutionStrategy.cacheDynamicVersionsFor 4, ¡®hours¡¯? }! ! ? .aar??le is a zip. you can unzip it to see what¡¯s inside.! ! ? Install the groovy shell to quickly verify that your groovy does what it is supposed to!
  • 13. Additional Resources ? Start by watching this Google IO talk:?http:// www.youtube.com/watch?v=LCJAgPkpmR0! ? Get up to speed with Groovy:?http://groovy.codehaus.org/ Groovy+style+and+language+feature+guidelines+for+Java +developers! ? Get up to speed with Gradle:?http://fb?ex.wordpress.com/ 2013/05/01/12-new-things-i-learned-from-a-three-day- gradle-training/! ? More info about resource merging ?http://tools.android.com/ tech-docs/new-build-system/resource-merging
  • 14. Thanks for coming Follow me on twitter @reidbaker