我有一个内部库,包含在不同的 Android 应用程序中。 该库依赖于 ICU4J。这意味着我们向最终 APK 添加了约 10MB。
该库使用 ICU4J 的子集,因此我想删除所有不必要的数据文件。
Currently ICU4J provides no tool for revealing these dependencies between data files, so trimming the data directly in the ICU4J project is a hit-or-miss affair. The key point when you remove data is to make sure to remove all dependencies on that data as well.
我想在构建应用程序时删除数据文件。
StackOverflow 上的一个相关问题:Exclude specific resources from an aar dep 。不幸的是,exploded-aar
目录不再存在。
您知道我可以在哪一步从 ICU4J 依赖项中删除文件吗?以下是我尝试删除 cjdict.dict
文件的方法:
tasks.create("excludeTask") << {
["java/com/ibm/icu/impl/data/icudt60b/brkitr/cjdict.dict"]
.collect { "${getGroup()}/${getName()}/${getVersion()}/${it}"}
.each {
// Question 2. From which dir should I remove the files?
File file = file("${buildDir}/intermediates/exploded-aar/${it}")
println("Excluding file " + file)
if (file.exists()) {
file.delete();
}
}
}
tasks.whenTaskAdded({
// Question 1. Before which task should I inject my excludeTask?
if (it.name.matches(/^transformClassesAndResources.*$/)) {
it.dependsOn excludeTask
}
})
- 问题 1:我应该在哪个任务之前注入(inject)
excludeTask
? - 问题 2:我应该从哪个目录中删除文件?
我知道 ICU4J 可以在 Android 7.0 中使用,而无需所有这些开销,但我希望为旧设备提供尽可能轻便的 APK。
Proguard/收缩资源对此不起作用(除非我错过了什么?)
最佳答案
用于切片 ICU 区域设置数据的更好机制是一个常见的功能请求,因此我们正在努力在即将发布的 ICU 版本中推出此功能(63 或 64,具体取决于情况进展)。同时,您可以自由地为我们的设计文档做出贡献:
https://docs.google.com/document/d/1Lt9sHy7VbMLA2KbbEpg-TgNAI8bqtetwM767enWjcUg/edit#
关于android - 在库中使用时从 ICU4J 中剥离数据文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49131848/