Ignore external security configuration of the external library

So, I want to add an external library to my project. The library itself is quite small, about 300 methods. But he is determined to be very liberal with his proguard configuration. I did a simple test with / without library and with / without proguard in the barebones project, and this is what I came up with

Proguard    Lib     Method Count
N           N       15631
Y           N       6370
N           Y       15945
Y           Y       15573

As you can see, with the proguard function turned on, the counter is ~ 6000. But at the moment I add lib, it counts arrows up to ~ 15000, despite the fact that the library itself consists of only 300 methods.

So my question is: how to ignore the proguard configuration of this particular library?

UPDATE:

Now it is impossible to connect to the android gradle plugin. I found an android error that has no priority at all. Please avoid answers that mention “this is not possible” and keep the question open until a workaround or formal solution is resolved. Otherwise, you get half the bounty without adding value. Thank you

+4
source share
1 answer

In this particular case, you have several options:

  • extract the classes.jar file from aar and include it as a regular jar dependency in your project (will not work if aar includes resources)
  • aar proguard
  • DexGuard, .
  • gradle , .

build.gradle :

afterEvaluate {
  // All proguard tasks shall depend on our filter task
  def proguardTasks = tasks.findAll { task ->
    task.name.startsWith('transformClassesAndResourcesWithProguardFor') }
  proguardTasks.each { task -> task.dependsOn filterConsumerRules }
}

// Let define our custom task that filters some unwanted
// consumer proguard rules
task(filterConsumerRules) << {
  // Collect all consumer rules first
  FileTree allConsumerRules = fileTree(dir: 'build/intermediates/exploded-aar',
                                       include: '**/proguard.txt')

  // Now filter the ones we want to exclude:
  // Change it to fit your needs, replace library with
  // the name of the aar you want to filter.
  FileTree excludeRules = allConsumerRules.matching {
    include '**/library/**'
  }

  // Print some info and delete the file, so ProGuard
  // does not pick it up. We could also just rename it.
  excludeRules.each { File file ->
    println 'Deleting ProGuard consumer rule ' + file
    file.delete()
  }
}

DexGuard (7.2.02+) build.gradle:

dexguard {
  // Replace library with the name of the aar you want to filter
  // The ** at the end will include every other rule.
  consumerRuleFilter '!**/library/**,**'
}

, ProGuard , consumerRuleFilter , .

+4

Source: https://habr.com/ru/post/1619370/


All Articles