fstephany
fstephany

Reputation: 2354

Stripping data files from ICU4J when used in a Library

I have an internal library that is included in different android apps. This library depends on ICU4J. This means we add ~10MB to the final APK.

The lib uses a subset of ICU4J so I would like to remove all the non-necessary data files.

From the ICU documentation:

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.

I'd like to remove the data files when the app is built.

One question on StackOverflow is related: Exclude specific resources from an aar dep. Unfortunately, the exploded-aar directory does not exist anymore.

Do you know at which step I can remove the files from the ICU4J dependency ? Here's what I've tried to remove the cjdict.dict file:

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
    }
})

I know that ICU4J can be used in Android 7.0 without all this overhead but I'd like to make the APK as light as I can for older devices.

Proguard/shrinking resources won't work for this (unless I miss something?)

Upvotes: 6

Views: 649

Answers (1)

sffc
sffc

Reputation: 6424

A better mechanism for slicing ICU locale data is a common feature request, so we are working on rolling this out in an upcoming ICU release (either 63 or 64 depending on how things go). In the mean time, freel free to contribute to our design doc:

https://docs.google.com/document/d/1Lt9sHy7VbMLA2KbbEpg-TgNAI8bqtetwM767enWjcUg/edit#

Upvotes: 0

Related Questions