gradle 101
Post on 12-Apr-2017
521 Views
Preview:
TRANSCRIPT
Why Gradle?
• Declarative vs Imperative
• Flexibility & Customization
• “Convention over Configuration” , well …convention is good but so is flexibility
Declarative vs Imperative
• Imperative : script how to do something, and as a result what you want to happen will happen
• Declarative: script what you would like to happen, and let the tool figure out how to do it
Declarative vs Imperative
• Imperative : script how to do something, and as a result what you want to happen will happen
• Declarative: script what you would like to happen, and let the tool figure out how to do it
Flexibility & Customization
• Supports Android’s diverse ecosystem, e.g. ABI, density , API level etc.
• Split apks for Play Store
• Still allows you to write plugins and tasks
Flexibility & Customization
• Supports Android’s diverse ecosystem, e.g. ABI, density , API level etc.
• Split apks for Play Store
• Still allows you to write plugins and tasks
Flexibility & Customization
• Supports Android’s diverse ecosystem, e.g. ABI, density , API level etc.
• Split apks for Play Store
• Still allows you to write plugins and tasks
Android Gradle Concepts
• Build Types - how the application is packaged, and how the compiler is called (mostly)Debug vs Release (vs. <other>)
• Product Flavors – mostly has to do with featurespaid vs. free
abi packaging
• Variants = Build Types + FlavorsfreeDebug , paidRelease , paidDebug , freeRelease
Android Gradle Concepts
• Build Types - how the application is packaged, and how the compiler is called (mostly)Debug vs Release (vs. <other>)
• Product Flavors – mostly has to do with featurespaid vs. free
abi packaging
• Variants = Build Types + FlavorsfreeDebug , paidRelease , paidDebug , freeRelease
Android Gradle Concepts
• Build Types - how the application is packaged, and how the compiler is called (mostly)Debug vs Release (vs. <other>)
• Product Flavors – mostly has to do with featurespaid vs. free
abi packaging
• Variants = Build Types + FlavorsfreeDebug , paidRelease , paidDebug , freeRelease
Sample Android build script: build.gradlebuildscript {
repositories {jcenter()
}dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'}
}
apply plugin: 'com.android.application'
android {compileSdkVersion 23buildToolsVersion "23.0.2"
defaultConfig {applicationId "com.example.test"minSdkVersion 15targetSdkVersion 23versionCode 1versionName "1.0"
}buildTypes {
release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}}
}
dependencies {compile fileTree(dir: 'libs', include: ['*.jar'])compile 'com.android.support:appcompat-v7:23.1.0'
}
Build Script: Repositories & Android Pluginbuildscript {
repositories {jcenter()
}dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'}
}
Example: Build Types
buildTypes {release {
minifyEnabled trueproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {minifyEnabled trueapplicationIdSuffix '.debug'versionNameSuffix '.debug'
}}
Default Config
defaultConfig {applicationId "com.example.test"minSdkVersion 15targetSdkVersion 23versionCode 1versionName "1.0"
}
Build Variants
• Variants = Build Types + FlavorsfreeDebug , paidRelease , paidDebug , freeRelease
Debug Release
Free freeDebug freeRelease
Paid paidDebug paidRelease
• Flavor Groups /Dimensionsadds another 3rd matrix to the mix… or 4th
Tip 2: Use Gradle wrapper!
./gradle wrapper --gradle-version 2.0
task wrapper(type: Wrapper) {gradleVersion = '2.0'
}
Tip 5: BuildConfig.java
public final class BuildConfig {public static final boolean DEBUG = Boolean.parseBoolean("true");public static final String APPLICATION_ID = "com.peirr.test.debug";public static final String BUILD_TYPE = "debug";public static final String FLAVOR = "";public static final int VERSION_CODE = 1;public static final String VERSION_NAME = "1.0.debug";
}
top related