2. 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
3. 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
4. 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
11. Build Variants specific files & deps
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.
12. BuildConfig
import 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()}";
"""
}
14. 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