apply plugin: 'java'
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.+' } } apply plugin: 'android' android { compileSdkVersion 17 buildToolsVersion: '17.0.0' }
src/main/java
src/main/resources
src/test/java
src/test/resources
src/main/AndroidManifest.xml
src/main/java
src/main/resources
src/main/res
src/main/assets
src/main/aidl
src/main/rs
src/main/jni
src/instrumentTest/java
src/instrumentTest/resources
src/instrumentTest/res
src/instrumentTest/assets
src/instrumentTest/aidl
src/instrumentTest/rs
src/instrumentTest/jni
android { sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs ['src'] res.srcDirs ['res'] } instrumentTest.setRoot('tests') } }
android { sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs ['src'] res.srcDirs ['res', 'res2'] } instrumentTest.setRoot('tests') } }
$ cd myproject/
$ cd gradle <taskName1> [taskName2]
$ cd gradle tasks [--all]
assemble
check
build
-> assemble + check
clean
jar
test
findBugsMain
findBugsTests
assemble
jar
check
test
findBugsMain
findBugsTests
build
-> assemble + check
clean
assemble
check
connectedCheck
deviceCheck
build
-> assemble + check
clean
assembleDebug + assembleRelease
android { defaultConfig { versionCode 12 versionName '2.0' minSdkVersion 14 targetSdkVersion 17 } }
def getVersionCode() { def code = ... return code } android { defaultConfig { versionCode getVersionCode() ... } }
android { buildTypes { debug { packageNameSuffix '.debug' versionNameSuffix '-DEBUG' } beta { ... } } }
src/main/AndroidManifest.xml
src/main/java
src/main/resources
src/main/res
src/main/assets
src/main/aidl
src/main/rs
src/main/jni
src/debug/...
src/beta/...
src/release/...
src/instrumentTest/java
src/instrumentTest/resources
src/instrumentTest/res
src/instrumentTest/assets
src/instrumentTest/aidl
src/instrumentTest/rs
src/instrumentTest/jni
assemble
jar
check
test
findBugsMain
findBugsTests
build
-> assemble + check
clean
assemble
assembleDebug + assembleBeta +
assembleRelease
check
connectedCheck
deviceCheck
build
-> assemble + check
clean
assembleDebug + assembleRelease
android { signingConfigs { debug { storeFile file('debug.keystore') } // buildTypes.debug already configured // to use signingConfigs.debug } }
android { buildTypes { debugRelease.initWith(buildTypes.release) debugRelease { debuggable true packageNameSuffix '.debugrelease' signingConfig signingConfig.debug } sourceSets.debugRelease.setRoot('src/release') } }
android { ... } android.buildTypes.each { type -> type.packageNameSuffix = ".$type.name" }
compile
runtime
testCompile
testRuntime
compile
apk
instrumentTestCompile
instrumentTestRuntime
debugCompile/Apk
releaseCompile/Apk
betaCompile/Apk
dependencies { compile fileTree(dir: 'libs', include '*.jar') } android { ... }
repositories { mavenCentral() } dependencies { compile 'com.actionbarsherlock:actionbarsherlock:4.3.1' betaCompile file('libs/protobuf.jar') } android { ... }
MyProject/ | settings.gradle + app/ | build.gradle + libs/ + lib1/ | build.gradle + lib2/ | build.gradle
include ':app' include ':libs:lib1' include ':libs:lib2'
dependencies { compile project(':libs:lib1') } android { ... }
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.4' } } apply plugin: 'android-library' android { compileSdkVersion 17 buildToolsVersion: '17.0.0' }
android { productFlavors { flavor1 { packageName 'com.example.flavor1' minSdkVersion 14 } flavor2 { packageName 'com.example.flavor2' } } }
src/main/AndroidManifest.xml
src/main/java
src/main/resources
src/main/res
src/main/assets
src/main/aidl
src/main/rs
src/main/jni
src/debug/...
src/beta/...
src/release/...
src/flavor1/...
src/instrumentTest/java
src/instrumentTest/resources
src/instrumentTest/res
src/instrumentTest/assets
src/instrumentTest/aidl
src/instrumentTest/rs
src/instrumentTest/jni
src/instrumentTestFlavor1/...
compile
runtime
testCompile
testRuntime
compile
apk
instrumentTestCompile
instrumentTestRuntime
debugCompile/Package
releaseCompile/Package
betaCompile/Package
flavor1Compile/Package
instrumentTestFlavor1Compile/Package
No Flavors:
debug | release | |
---|---|---|
debug | release | |
- | - |
With Flavors:
debug | release | |
---|---|---|
Flavor1 | Flavor1Debug | Flavor1Release |
Flavor2 | Flavor2Debug | Flavor2Release |
android { flavorGroups 'abi', 'version' productFlavors { arm { flavorGroup 'abi' } paid { flavorGroup 'version' packageName '.paid' } } }
debug | release | ||
---|---|---|---|
paid | arm | paid-arm-debug | paid-arm-release |
paid | x86 | paid-x86-debug | paid-x86-release |
paid | mips | paid-mips-debug | paid-mips-release |
free | arm | free-arm-debug | free-arm-release |
free | x86 | free-x86-debug | free-x86-release |
free | mips | free-mips-debug | free-mips-release |
Multiple Source Folders, Single Output
src/main/java
src/free/java
src/mips/java
src/debug/java
Overlays
src/debug/res
↓
src/free/res
↓
src/mips/res
↓
src/main/res
Priority Order
android.buildTypes.release.signingConfig
↓
android.productFlavors.free.signingConfig
↓
android.productFlavors.mips.signingConfig
↓
android.defaultConfig.signingConfig
Overlays + Suffix
android.productFlavors.free.packageName
↓
android.productFlavors.mips.packageName
↓
android.defaultConfig.packageName
↓
src/main/AndroidManifest.xml
+ android.buildTypes.debug.packageNameSuffix
src/instrumentTest, src/instrumentTestFlavor1
instrumentTestCompile, instrumentTestFlavor1Compile
AndroidManifest.xml
check
connectedCheck
deviceCheck
'com.android.tools.buid:gradle:0.5'
android.buildToolsVersion '17.0'
Presentation is available on github