Skip to content

Instantly share code, notes, and snippets.

@fjtorres
Last active April 6, 2017 10:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjtorres/5593683 to your computer and use it in GitHub Desktop.
Save fjtorres/5593683 to your computer and use it in GitHub Desktop.
build.gradle android studio module
import org.apache.tools.ant.filters.ReplaceTokens
// Configure default profile
if (!project.hasProperty("profile")) {
project.set("profile", "dev")
}
// Load application properties by profile
def props = new Properties()
file("../application-${profile}.properties").withInputStream {
stream -> props.load(stream)
}
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.6'
}
}
apply plugin: 'android'
repositories {
maven { url 'http://repo1.maven.org/maven2' }
maven { url 'https://oss.sonatype.org/content/groups/public/' }
}
dependencies {
compile files('libs/android-support-v4.jar')
compile 'it.restrung:restrung:1.0-SNAPSHOT'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 17
}
}
// Filtering resources
task filteringResources(type:Copy) {
from('src/main/res/') {
include '**/*.xml'
for (String propName:props.stringPropertyNames()){
filter(ReplaceTokens, tokens: [
"{${propName}": props.get(propName)
],
beginToken: '$',
endToken: '}'
)
}
}
from('src/main/res/') {
exclude '**/*.xml'
}
into 'build/target/filtered-resources/'
includeEmptyDirs = true
}
configure(filteringResources) {
group = BasePlugin.BUILD_GROUP
description = 'Filtering task'
}
tasks.whenTaskAdded { task ->
if (task.name == 'generateDebugBuildConfig') {
task.dependsOn filteringResources
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment