Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using gradle extra properties to manage Android dependency versioning
// app module build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "com.segunfamisa.gradleextraproperties"
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:design:$rootProject.supportLibraryVersion"
compile "com.android.support:percent:$rootProject.supportLibraryVersion"
compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:gridlayout-v7:$rootProject.supportLibraryVersion"
//play services
compile "com.google.android.gms:play-services-location:$rootProject.playServicesVersion"
compile "com.google.android.gms:play-services-gcm:$rootProject.playServicesVersion"
testCompile "junit:junit:$rootProject.jUnitVersion"
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-alpha4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext {
// sdk and tools
minSdkVersion = 14
targetSdkVersion = 23
compileSdkVersion = 23
buildToolsVersion = '23.0.2'
supportLibraryVersion = '23.4.0'
playServicesVersion = '9.0.0'
jUnitVersion = '4.12'
}
@truongngoclinh

This comment has been minimized.

truongngoclinh commented Jun 12, 2017

Thank you for your sharing.
Noted that we can create own config.gradle file and push all the ext values into it, then using across all modules.
Pls check my gist:
https://gist.github.com/truongngoclinh/af143066468ec5456cea6867350331fe#file-config-gradle

@younes372

This comment has been minimized.

younes372 commented Mar 8, 2018

tax

@juancoob

This comment has been minimized.

juancoob commented Jul 17, 2018

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment