Proguard – do not obfuscate Kotlin data classes

To fix the problem I moved the model classes to model package and added new ProGuard rule for the package. -keep class com.company.myfeature.model.** { *; } Another solution would be to use @Keep annotation from support library to disable the obfuscation for the class: @Keep data class MyRequestBody(val value: String) Using @Keep may cause problems … Read more

Proguard keep class names?

Use the -keepnames option in your proguard.cfg Refer to the manual https://www.guardsquare.com/manual/configuration/usage#keepoptions -keepnames class_specification Short for -keep,allowshrinking class_specification Specifies classes and class members whose names are to be preserved, if they aren’t removed in the shrinking phase. For example, you may want to keep all class names of classes that implement the Serializable interface, so … Read more

What is the difference between consumer-rules.pro and proguard-rules.pro in Android?

I’ll try to answer each question, but let me know if something doesn’t make sense! 1. Will all of the modules code be obfuscated by the rules of the main modules pro-guard rules even if the module does not specify any rules? Obfuscation doesn’t work that way. When you enable the minifyEnabled property in your … Read more

Removing Log call using proguard

You shouldn’t specify the ‘*’ wildcard, because that includes methods like ‘Object#wait()’. Better explicitly list the methods: -assumenosideeffects class android.util.Log { public static boolean isLoggable(java.lang.String, int); public static int v(…); public static int i(…); public static int w(…); public static int d(…); public static int e(…); } This option is only relevant if optimization is … Read more

android studio 3.1 Warning: The rule `-keep public class *extends java.lang.annotation.Annotation {

As mentioned in the question’s comments by @arcone1, @Vincent Mattana & confirmed by @random, the issue is resolved in Android Studio 3.2. From the issue in Google Issue Tracker: To clarify, this is a warning, not an error, from R8, which we use to compute the list of classes for the main dex, in legacy … Read more

What is the difference between proguard-android.txt and proguard-rules.pro ? – Android

The getDefaultProguardFile(‘proguard-android.txt’) method obtains the default ProGuard settings from the Android SDK tools/proguard/ folder. The proguard-android-optimize.txt file is also available in this Android SDK folder with the same rules but with optimizations enabled. ProGuard optimizations perform analysis at the bytecode level, inside and across methods to help make your app smaller and run faster. Android … Read more

How to use Kotlin with Proguard

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 … Read more