Kotlin AAR library with proguard: how to store extension methods?

I am writing a new Kotlin library module to add commonly used classes and extension methods. I am compiling each extension file (eg BitmapExtensions.kt) into one file called Extensions using JvmMultifileClass

:

@file:JvmName("Extensions")
@file:JvmMultifileClass

fun Bitmap.crop(cropRect: Rect) = ...

      

As part of our company's IP policy, I need to obfuscate a library through proguard before it turns into any consumer project. So I need a proguard rule to keep these extension methods from getting thrown away.

At first glance, it seems to work below, checking the generated AAR classes.jar, which shows that the extension methods still exist and their insides have been obfuscated. But when I actually compile in a consumer project, I get unresolved references to whatever extension method I have referenced.

-keepclassmembernames class mycompany.kotlin.util.Extensions {
    <methods>;
}

      

When I disable minification, the project builds correctly.

How can I obfuscate my library and keep my kotlin extensions?

edit: It looks like using keep

for the whole package and even pointing out is -dontshrink

not enough. These methods simply cannot be specified in a consumer application.

edit2: I believe I have narrowed this down to a file .kotlin_module

in the / META-INF / section that gets deleted when minifyEnabled=true

. This appears to be ONLY the difference between my minified and unminified classes. Something deletes this file ... or prevents it from being generated.

+3


source to share


1 answer


I upgraded to gradle 4.1 milestone 1. The metadata file is .kotlin_module

no longer deleted when minifyEnabled=true

, and my consumer application can now correctly use extension methods from lib.



0


source







All Articles