8

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"
         }
}

4 Answers4

24

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

DropDrage
  • 725
  • 8
  • 9
7

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

  • This is strange but life saver – Aamir Altaf Kathu Jul 04 '22 at 07:10
  • Thanks! This solved my problem. In my case the issue was that there were two files with same name in two different modules. The functions in one of the files were not being picked up. Renaming that file resolved the name confusion and all's working again. – Adi B Apr 03 '23 at 13:42
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

Alex Styl
  • 3,982
  • 2
  • 28
  • 47
0

I had two files named exactly the same, 1 in my main project and 1 in my test package. For some reason this conflicts, after renaming the file in my test package, things worked again.

J. Doe
  • 12,159
  • 9
  • 60
  • 114