gradle presentation
DESCRIPTION
Small introduction to gradle for androidTRANSCRIPT
![Page 1: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/1.jpg)
Gradle not just an ANT replacement
![Page 2: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/2.jpg)
Goals of Gradle (from official docs)● Make it easy reuse code and resources (.aar)● Make it easy to create several variants of an application● Make it easy to configure, extend and customize the
build process● Good IDE integration
![Page 3: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/3.jpg)
About Gradle
● Is based on groovy:○ binary-compatible with java○ Most java code is syntactically valid on Groovy○ The gradle installation comes with groovy
● You better use a gradle wrapper for your android projects
![Page 4: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/4.jpg)
Android Studio
● If something goes wrong, use gradle on the command line
● use this button: ● One update can “break” your project● If something goes wrong, use gradle on the command
line
![Page 5: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/5.jpg)
Basic gradle configbuildscript {
repositories {
mavenCentral()
} dependencies {
classpath 'com.android.tools.build:gradle:0.6.0+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
}
![Page 6: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/6.jpg)
Adding libsdependencies {
// MavenCentral deps
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:appcompat-v7:19.0.0'
compile 'com.squareup.retrofit:retrofit:1.2.2'
compile 'com.squareup.okhttp:okhttp:1.2.1'
// project dep:
compile project(“:libraries:lib1”)
// jar dep:
compile files(‘libs/a.jar”, “libs/b.jar”)
compile fileTree(dir: “libs”, include: “*.jar”)
}
![Page 7: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/7.jpg)
Basic gradle commands$ gradle tasks
$ gradle tasks --all
$ gradle assembleDebug
$ gradle assembleRelease
$ gradle clean
$ gradle installDebug
$ gradle uninstallAll
![Page 8: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/8.jpg)
Gradle build customizationandroid {
compileSdkVersion 19
defaultConfig {
versionCode 1
versionName "1.0"
minSdkVersion 16
targetSdkVersion 16
}
}
![Page 9: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/9.jpg)
Build TypesbuildTypes {
debug {
packageNameSuffix ".debug"
}
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android-
optimize.txt')
}
}
$ gradle installFreeDebug
![Page 10: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/10.jpg)
Build VariantsproductFlavors {
free {
packageName "com.bitcoinlab.android.free"
buildConfig “public static final boolean FULL_VERSION =
false;”
}
full {
packageName "com.bitcoinlab.android.full"
versionName "2.0"
versionCode 20
buildConfig “public static final boolean FULL_VERSION =
true;”
signingConfig signingConfigs.myConfig
}
}
$ gradle installFullDebug
![Page 11: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/11.jpg)
src/full/java/src/”packagename”/file.java
src/full/res/values/strings.xml
src/full/AndroidManifest.xml
dependencies {
fullCompile ‘com.squareup.okhttp:okhttp:1.2.1'
}
A source file can’t exists on main src folder and at
the same time on a flavour src folder: put a class into
main, or in every buildType but not both.
Build Variants specific files & deps
![Page 12: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/12.jpg)
BuildConfigimport java.text.SimpleDateFormat
def buildTime() {
def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'")
df.setTimeZone(TimeZone.getTimeZone("UTC"))
return df.format(new Date())
}
defaultConfig {
buildConfig """\
public static final String GIT_SHA = "${gitSha()}";
public static final String BUILD_TIME = "${buildTime()}";
"""
}
![Page 13: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/13.jpg)
Android Studio Integration
![Page 14: Gradle presentation](https://reader034.vdocument.in/reader034/viewer/2022042513/54c60ec24a7959252f8b45cb/html5/thumbnails/14.jpg)
Some things you can do with gradle● free/paid apk
● debug/release version
● beta/alpha/”any git branch” apk
● Use multiple flavors + multiple-apk play store support to distribute
smaller apks (depending on screen size or android version)
● build your customized integration and test server in minutes