• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Calling kotlin from java shows "Cannot resolve symbol" for classes and methods called

There are two modules:
  1. app (main/application module which contains both Java and Kotlin classes)
  2. lib-wrapper (Android-library module which contains Java classes)
lib-wrapper is published on the Amazon S3 bucket and used as a library dependency in app module. Proguard rules are applied for the lib-wrapper. It was all working fine till now.

Then converted all the classes of lib-wrapper from java to kotlin.
  • Now, all the java classes (in app module) which are calling lib-wrapper methods show “Cannot resolve symbol” in red.

  • There is no problem with kotlin classes (in app module) which are calling lib-wrapper methods.

  • Even with “Cannot resolve symbol” in java classes, app compiles and runs without error. But for new users it is very tough to use lib-wrapper as it won’t show library classes and methods as an auto-complete suggestion.

  • Decompiling the apk file, lib-wrapper classes shows all intended classes and methods are public and public members are plain/de-obfuscated. (Which is expected.)

  • If I disable Proguard (“minifyEnabled false” in lib-wrapper’s build.gradle), everything works fine.
So I added below kotlin specific proguard rules in lib-wrapper's proguard-rules.pro file, but didn't help :
-keep class kotlin.*.* { *; }
-keep class kotlin.Metadata { *; }
-dontwarn kotlin.**
-keepclassmembers class **$WhenMappings {
<fields>;
}
-keepclassmembers class kotlin.Metadata {
public <methods>;
}
-assumenosideeffects class kotlin.jvm.internal.Intrinsics {
public static void checkParameterIsNotNull(java.lang.Object, java.lang.String);
}

Plugins used in lib-wrapper’s build.gradle file:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'
apply plugin: 'org.jetbrains.dokka-android'

Plugins used in app module’s build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

Any help would be appreciated. Thanks in advance.
 
There are two modules:
  1. app (main/application module which contains both Java and Kotlin classes)
  2. lib-wrapper (Android-library module which contains Java classes)
lib-wrapper is published on the Amazon S3 bucket and used as a library dependency in app module. Proguard rules are applied for the lib-wrapper. It was all working fine till now.

Then converted all the classes of lib-wrapper from java to kotlin.
  • Now, all the java classes (in app module) which are calling lib-wrapper methods show &#8220;Cannot resolve symbol&#8221; in red.
  • There is no problem with kotlin classes (in app module) which are calling lib-wrapper methods.
  • Even with &#8220;Cannot resolve symbol&#8221; in java classes, app compiles and runs without error. But for new users it is very tough to use lib-wrapper as it won&#8217;t show library classes and methods as an auto-complete suggestion.
  • Decompiling the apk file, lib-wrapper classes shows all intended classes and methods are public and public members are plain/de-obfuscated. (Which is expected.)
  • If I disable Proguard (&#8220;minifyEnabled false&#8221; in lib-wrapper&#8217;s build.gradle), everything works fine.
So I added below kotlin specific proguard rules in lib-wrapper's proguard-rules.pro file, but didn't help :
-keep class kotlin.*.* { *; }
-keep class kotlin.Metadata { *; }
-dontwarn kotlin.**
-keepclassmembers class **$WhenMappings {
;
}
-keepclassmembers class kotlin.Metadata {
public ;
}
-assumenosideeffects class kotlin.jvm.internal.Intrinsics {
public static void checkParameterIsNotNull(java.lang.Object, java.lang.String);
}

Plugins used in lib-wrapper&#8217;s build.gradle file:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'
apply plugin: 'org.jetbrains.dokka-android'

Plugins used in app module&#8217;s build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

Any help would be appreciated. Thanks in advance.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones