1. Are you ready for the Galaxy S20? Here is everything we know so far!

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

Discussion in 'Android Development' started by Anand Suthar, Apr 6, 2021.

  1. Anand Suthar

    Anand Suthar Lurker
    Thread Starter

    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 {
    -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.

    1. Download the Forums for Android™ app!


  2. leeladonna

    leeladonna Lurker


Share This Page