ppamorim

Untitled

Oct 21st, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 2.09 KB | None | 0 0
  1. def toCamelCase(String string) {
  2.     String result = ""
  3.     string.findAll("[^\\W]+") { String word ->
  4.         result += word.capitalize()
  5.     }
  6.     return result
  7. }
  8.  
  9. afterEvaluate { project ->
  10.     Configuration runtimeConfiguration = project.configurations.getByName('compile')
  11.     ResolutionResult resolution = runtimeConfiguration.incoming.resolutionResult
  12.     // Forces resolve of configuration
  13.     ModuleVersionIdentifier module = resolution.getAllComponents().find { it.moduleVersion.name.equals("play-services") }.moduleVersion
  14.  
  15.     String prepareTaskName = "prepare${toCamelCase("${module.group} ${module.name} ${module.version}")}Library"
  16.     File playServiceRootFolder = project.tasks.find { it.name.equals(prepareTaskName) }.explodedDir
  17.  
  18.     Task stripPlayServices = project.tasks.create(name: 'stripPlayServices', group: "Strip") {
  19.         inputs.files new File(playServiceRootFolder, "classes.jar")
  20.         outputs.dir playServiceRootFolder
  21.         description 'Strip useless packages from Google Play Services library to avoid reaching dex limit'
  22.  
  23.         doLast {
  24.             copy {
  25.                 from(file(new File(playServiceRootFolder, "classes.jar")))
  26.                 into(file(playServiceRootFolder))
  27.                 rename { fileName ->
  28.                     fileName = "classes_orig.jar"
  29.                 }
  30.             }
  31.             tasks.create(name: "stripPlayServices" + module.version, type: Jar) {
  32.                 destinationDir = playServiceRootFolder
  33.                 archiveName = "classes.jar"
  34.                 from(zipTree(new File(playServiceRootFolder, "classes_orig.jar"))) {
  35.                     exclude "com/google/android/gms/games/**"
  36.                     exclude "com/google/android/gms/plus/**"
  37.                     exclude "com/google/android/gms/drive/**"
  38.                 }
  39.             }.execute()
  40.             delete file(new File(playServiceRootFolder, "classes_orig.jar"))
  41.         }
  42.     }
  43.  
  44.     project.tasks.findAll { it.name.startsWith('prepare') && it.name.endsWith('Dependencies') }.each { Task task ->
  45.         task.dependsOn stripPlayServices
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment