Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Kotlin with Proguard

I'm trying to add Kotlin to my project and I need to use proguard. Which rules should I add to proguard to support Kotlin?

Thank you

like image 773
Fábio Carballo Avatar asked Nov 05 '15 14:11

Fábio Carballo


People also ask

How do you use Kotlin ProGuard?

if you use android studio, proguards comes with default. But you should on "Enables code shrinking" and "Enables resource shrinking" options for your code security and code optimization. open your gradile file and check below. Show activity on this post.

Does ProGuard work on Kotlin?

ProGuard will apply the same obfuscations to Kotlin identifiers in metadata, such as class or member names, to match those in the Java class files. This ensures that, even where the Kotlin metadata is required, no sensitive names remain in the metadata.


1 Answers

You don't need to do anything special. Kotlin works with ProGuard out of the box. But you may face some strange errors when processing your application with ProGuard. In this case just add

-dontwarn kotlin.** 

Also if you want to get rid of null checks at runtime you may use the following rule:

-assumenosideeffects class kotlin.jvm.internal.Intrinsics {     static void checkParameterIsNotNull(java.lang.Object, java.lang.String); } 
like image 174
Michael Avatar answered Sep 27 '22 22:09

Michael