Sunday, 5 June 2022

Set noCompress for only one productFlavor

I'm trying to set androidResources.noCompress for only one product flavor

When I try this

flavorDimensions "ring"
productFlavors {
    innerRing {
        dimension "ring"
    }
    outerRing {
        dimension "ring"
        androidResources {
            noCompress 'so'
        }
    }
}

Both innerRing and outerRing end up with .so files uncompressed. I believe this is due to gradle configuring all the product flavors statically. (see here)

But when I try to change noCompress afterEvaluate

afterEvaluate {
    android.applicationVariants.all { variant ->
        def ring = variant.getProductFlavors().get(0).name
        if (ring == "outerRing") {
            println("Don't compress .so files for outer ring build")
            android.androidResources.noCompress = ['so']
        }
    }
}

I get this error

com.android.build.gradle.internal.dsl.AgpDslLockedException: 
It is too late to modify internalNoCompressList
It has already been read to configure this project.
Consider either moving this call to be during evaluation,
or using the variant API.

How can I use the variant API to fix this? Any help is appreciated!



from Set noCompress for only one productFlavor

No comments:

Post a Comment