Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard and Kotlin-Reflect/Kotlin Annotations

Looking for some help from someone who puts the pro in proguard.

Annotations used by kotlin-reflect (required dependency for jackson-module-kotlin v v2.8.8) are getting stripped out after upgrading to kotlin 1.1.2-3. The error from proguard is: Warning:kotlin.reflect.jvm.internal.impl.descriptors.CallableDescriptor: can't find referenced class org.jetbrains.annotations.ReadOnly

This is happening for a few annotations, not just ReadOnly. We have tried adding a good ol' catch all but the error still exists:

-keep class org.jetbrains.kotlin.** { *; }
-keep class org.jetbrains.annotations.** { *; }
-keepclassmembers class ** {
  @org.jetbrains.annotations.ReadOnly public *;
}

Looking at the source for ReadOnly it is an @interface with java.lang.annotations.* imported for @Documented, @RetentionPolicy.CLASS, @Target

like image 684
Bryan Avatar asked May 24 '17 14:05

Bryan


2 Answers

Or a shorter version:

-dontwarn kotlin.reflect.jvm.internal.**

like image 125
Klemens Zleptnig Avatar answered Oct 30 '22 05:10

Klemens Zleptnig


The fix for us was to add dontwarn for the reflect warnings.

-dontwarn kotlin.reflect.jvm.internal.impl.descriptors.CallableDescriptor
-dontwarn kotlin.reflect.jvm.internal.impl.descriptors.ClassDescriptor
-dontwarn kotlin.reflect.jvm.internal.impl.descriptors.ClassifierDescriptorWithTypeParameters
-dontwarn kotlin.reflect.jvm.internal.impl.descriptors.annotations.AnnotationDescriptor
-dontwarn kotlin.reflect.jvm.internal.impl.descriptors.impl.PropertyDescriptorImpl
-dontwarn kotlin.reflect.jvm.internal.impl.load.java.JavaClassFinder
-dontwarn kotlin.reflect.jvm.internal.impl.resolve.OverridingUtil
-dontwarn kotlin.reflect.jvm.internal.impl.types.DescriptorSubstitutor
-dontwarn kotlin.reflect.jvm.internal.impl.types.DescriptorSubstitutor
-dontwarn kotlin.reflect.jvm.internal.impl.types.TypeConstructor

These annotations exist in kotlin-compiler which is why proguard can't find them. Just ignore the warning instead of adding kotlin-compiler as a dependency (as this issue suggests Cannot resolve symbol @ReadOnly and @Mutable in Kotlin 1.1.0 compilation).

This may be a bug in kotlin-reflect; they should provide proguard rules to hide this from integrating apps.

like image 8
Bryan Avatar answered Oct 30 '22 06:10

Bryan