7

I have a extension method:

fun StoresClientFragment?.onClickButtonBack(){
   this?.listener?.onStoresFragmentClickBtnMenu()
}

The app installs without any errors; but when the method is invoked at runtime it gives me the following error:

java.lang.NoSuchMethodError: No static method onClickButtonBack (Lcom/app/common_client/ui/fragment /stores/StoresClientFragment;) V in class Lcom/app/common_client/commons/CommonsAppTypeGroupKt; or its super classes (declaration of 'com.app.common_client.commons.CommonsAppTypeGroupKt' appears in /data/app/com.myapp.client-DWp0y3iNC3tsmBZkowlpfw==/base.apk!classes2.dex).

I have multidex enabled

In build.gradle

android {
    defaultConfig {
        multiDexEnabled = true
    }
}

dependencies {
   implementation 'androidx.multidex:multidex:2.0.1'
}

In Application class

class ApplicationClient : MultiDexApplication(){
}

In the Manifest

<application
        android:name=".commons.application.ApplicationClient"

Note: I am using product flavors and modules, that method is in a src shared by some product flavors

sourceSets {
         flavorA {
             java.srcDirs + = "src/sharedFolder/java" //here is 'onClickButtonBack' method
         }
         flavorB {
             java.srcDirs + = "src/sharedFolder/java"
         }
}
3
  • did you try by making entry into the proguard file something like below : -keep class com.app.common_client.ui.fragment.stores.** {*;} Mar 2, 2021 at 16:55
  • I don't have proguard enabled, I have it like this "minifyEnabled false"; Should I still add that to proguard? Mar 2, 2021 at 17:03
  • Maybe the problem is that you are trying to access to that method from "flavorB" compilation? Mar 2, 2021 at 17:37

3 Answers 3

21

Build -> Rebuild Project helped me. It seems to be a bug in Android Studio code caching

5

I have solved it, however I don't know why, the only thing I did was change the name of the file where the method was.

MyFile.kt by MyNewFile.kt

fun StoresClientFragment? .onClickButtonBack () {
     this? .listener? .onStoresFragmentClickBtnMenu ()
}

I hope it helps someone who is experiencing the same thing, and I would also like if there is someone who knows why that has worked, share it, thank you

1
0

I solved it in my case for changing the package of the file it was trying to get the method from.

My setup was 2 kotlin modules (A depends on B). Both had the same package name and class. When I was trying to use B.method() from A, it seems like it was trying to call A.method() instead.

not an expert on this. just what i noticed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.