Hey, anyone is able to minimify an Android library...
# multiplatform
s
Hey, anyone is able to minimify an Android library in KMP ? I can't get the new AGP9 plugin to work when I enable it with this:
Copy code
optimization {
    minify = true
    keepRules.apply {
       file(getDefaultProguardFile("proguard-android-optimize.txt", layout.buildDirectory))
       file("<http://proguard-rules.pro|proguard-rules.pro>")
    }
}
I get an error
Copy code
Could not determine the dependencies of task ':lib:minifyAndroidMainWithR8'.
> Cannot query the value of this property because it has no value available.
I'm using the com.android.kotlin.multiplatform.library:9.1.1
v
it looks like you're trying to minify a library (not application) ?
👍 1
a
I guess the goal is to minimify the library when it is consumed by the application. Try using:
Copy code
kotlin {
    android {
        optimization {
            minify = true
            consumerKeepRules.apply {
                publish = true // needed since AGP 9 
                file("<http://proguard-rules.pro|proguard-rules.pro>")
            }
        }
    }
}
Related doc: https://developer.android.com/kotlin/multiplatform/plugin#consumer-keep-rules
👎 1
m
@Smoothie What're trying to do is quite impossible with
android-kotlin-multiplatform-library
plugin and the 'official' way would be to extract it to android-only library module (via
android-library
plugin) and add it as a dependency to multiplatform module, which would be tedious for bigger libs. What I've actually done to overcome this issue is I've written gradle plugin which decompress built AAR, then uses R8 to obfuscate/minimise files and finally repackage library, back to AAR. Please @Anton Makeev, if You're reading this, why is it not possible to obfuscate/minimise multiplatform library easier? There can actually be cases where it is needed.
👀 1
s
Yeah I minimify a library, not an application, because we always delivered minimified/obfuscated library to client as an .aar most of the time (sometime maven, but it's minimified too).
☝️ 1
👌 1
I will do it manually but it's tedious for something that was working out of the box before, everything worked much better for us with previous android kmp way of working
g
I was experiencing the same issue with my library and found that this worked for me to give me the result I had before AGP 9:
Copy code
optimization {
    minify = true
    keepRules.apply {
        file("proguard-rules.pro")
    }
    consumerKeepRules.apply {
        file("proguard-rules.pro")
        publish = true
    }
}
🙌 2
👍 1
m
Huh, I've checked this out and actually do work. I see it is marked unstable with @Incubating , but I do hope it will stick. It's just weird that's configured in different block. I removed consumer keep rules to see if it works without them, but it doesn't which is also quite confusing
Anyway, thanks for the tip
s
Thank's a lot ! I will try it at work tomorrow, I feel really dumb to not have though about it
g
No worries, it is a bit confusing to need both but as Marcin mentioned it is marked as incubating. I'm still trying to fix a few issues with my setup but will post those if useful once fixed.