大佬教程收集整理的这篇文章主要介绍了android – 忽略外部库的proguard配置,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Proguard Lib Method Count N N 15631 Y N 6370 N Y 15945 Y Y 15573
如您所见,启用proguard后,计数为~6000.但是当我添加lib时,尽管库本身只有大约300种方法,但计数却达到了大约15000.
所以我的问题是,如何忽略这个特定库的proguard配置?
更新:
现在无法使用android gradle插件.我发现android bug没有优先权.请避免提及“不可能”的答案,并在可能的解决方法或官方决定之前保持问题.否则,你将收集一半的赏金而不增加价值.谢谢!
>从aar中提取classes.jar文件,并将其作为普通jar依赖项包含在项目中(当aar包含资源时不起作用)
>更改aar并从中删除使用者proguard规则
>使用DexGuard可以过滤掉不需要的消费者规则
>做一些gradle hacking,见下文
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's 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将仅包含与模式匹配的消费者规则.
以上是大佬教程为你收集整理的android – 忽略外部库的proguard配置全部内容,希望文章能够帮你解决android – 忽略外部库的proguard配置所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。