Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoSuchMethodError: No static method 'myMethod'

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"
         }
}
like image 995
Jhelsin Mijael Quispe Garcia Avatar asked Feb 16 '26 08:02

Jhelsin Mijael Quispe Garcia


2 Answers

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

like image 147
DropDrage Avatar answered Feb 18 '26 05:02

DropDrage


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

like image 40
Jhelsin Mijael Quispe Garcia Avatar answered Feb 18 '26 05:02

Jhelsin Mijael Quispe Garcia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!