| apply from: "../commonHeader.gradle" |
| buildscript { apply from: "../commonBuildScript.gradle", to: buildscript } |
| |
| |
| if (buildToolsVersion < '21.0.0') { |
| println ("Warning : this sample requires build-tools version 21 or above") |
| } |
| |
| apply plugin: 'com.android.application' |
| |
| android { |
| compileSdkVersion 21 |
| buildToolsVersion = rootProject.ext.buildToolsVersion |
| |
| defaultConfig { |
| versionCode 12 |
| minSdkVersion 16 |
| targetSdkVersion 20 |
| } |
| } |
| |
| repositories { |
| maven { url System.env.CUSTOM_REPO } |
| } |
| |
| dependencies { |
| compile 'com.google.code.gson:gson:2.3' |
| } |
| |
| // JarJar tasks and related configurations\ |
| configurations { |
| // create new configuration for JarJar |
| jarjar |
| } |
| |
| dependencies { |
| // add jarjar artifact to jarjar configuration |
| jarjar 'com.googlecode.jarjar:jarjar:1.3' |
| } |
| |
| android.applicationVariants.all { variant -> |
| // create task name |
| String jarJarTaskName = "jarJar${variant.name.capitalize()}"; |
| |
| def workingDir = project.file('build/intermediates/jarjar'); |
| // input file are the compiled files and the gson lib. |
| def inputDir = variant.javaCompiler.destinationDir |
| def outputLibrary = new File(workingDir, 'classes.jar').getCanonicalFile() |
| |
| // define task |
| def jarJarTask = task("${jarJarTaskName}") { |
| logger.info "${jarJarTaskName} inputDir: ${inputDir}" |
| logger.info "${jarJarTaskName} outputLibrary: ${outputLibrary}" |
| |
| inputs.file inputDir |
| outputs.file outputLibrary |
| |
| doLast { |
| // in Ant |
| project.ant { |
| // define jarjar task, for classpath is used path from jarjar configuration |
| taskdef name: 'jarjar', |
| classname: 'com.tonicsystems.jarjar.JarJarTask', |
| classpath: configurations.jarjar.asPath |
| |
| // start jarjar task |
| jarjar(jarfile: outputLibrary) { |
| // input is our inputDir |
| fileset(dir: inputDir) |
| // this project has only ONE dependency, gson so this is easy but obviously, this is not |
| // the best way to include compile dependencies. |
| zipFileset(src: variant.compileLibraries.toArray()[0]) |
| // rule to repackage gson to new package |
| rule pattern: 'com.google.gson.**', result: 'com.google.repacked.gson.@1' |
| } |
| } |
| |
| // replace jar generated by compile with jar generated by JarJar |
| variant.dex.inputFiles = [outputLibrary] |
| // and remove our preDex'ed libraries. |
| variant.dex.libraries = [] |
| } |
| } |
| |
| // plan task to be started between Compile task and Dex task |
| // if the task was using proguard, we would need to reset the proguard inputs rather than dex. |
| variant.dex.dependsOn jarJarTask |
| jarJarTask.dependsOn variant.javaCompiler |
| } |