java.lang.NoSuchMethodError: no static method ONLY for release version, not debug

Viewed 212

I'm getting a java.lang.NoSuchMethodError: no static method for a Kotlin function when loading it from C++, but it only happens when I run the Flutter RELEASE. In debug, it works without any errors.

03-05 15:40:16.174  8799  8799 F zygote64: thread.cc:2036] No pending exception expected: java.lang.NoSuchMethodError: no static method "Lcom/myapp/flutter_app/JNI;.loadWavAsset(Ljava/lang/String;Ljava/lang/String;F)Z"
03-05 15:40:16.174  8799  8799 F zygote64: thread.cc:2036]   at java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader, java.lang.String) (Runtime.java:-2)
03-05 15:40:16.174  8799  8799 F zygote64: thread.cc:2036]   at java.lang.String java.lang.Runtime.doLoad(java.lang.String, java.lang.ClassLoader) (Runtime.java:1099)
03-05 15:40:16.174  8799  8799 F zygote64: thread.cc:2036]   at void java.lang.Runtime.loadLibrary0(java.lang.ClassLoader, java.lang.String) (Runtime.java:1014)
03-05 15:40:16.174  8799  8799 F zygote64: thread.cc:2036]   at void java.lang.System.loadLibrary(java.lang.String) (System.java:1657)
03-05 15:40:16.174  8799  8799 F zygote64: thread.cc:2036]   at void com.myapp.flutter_app.MainActivity.<init>() (:-1)
03-05 15:40:16.174  8799  8799 F zygote64: thread.cc:2036]   at java.lang.Object java.lang.Class.newInstance() (Class.java:-2)
03-05 15:40:16.174  8799  8799 F zygote64: thread.cc:2036]   at android.app.Activity android.app.Instrumentation.newActivity(java.lang.ClassLoader, java.lang.String, android.content.Intent) (Instrumentation.java:1195)

Here's the kotlin file:

package com.myapp.flutter_app

import android.content.Context
//... other imports

class JNI(val _context: Context) {


    companion object {
        val TAG: String = "JNI.kt";

        lateinit var context: Context;

        @JvmStatic
        public fun loadWavAsset(player: String, assetPath: String, pan: Float): Boolean {

Here's how C++ loads it:

    static void getStaticMethodAndCache(JNIEnv *env, jmethodID *cacheHere, jclass *javaClass, std::string methodName, std::string methodSignature)
    {
        *cacheHere = env->GetStaticMethodID(*javaClass, methodName.c_str(), methodSignature.c_str());
        assert(*cacheHere != NULL);
    }


    getStaticMethodAndCache(env, &loadWavAssetMethod, &JNIClass,
                                                     "loadWavAsset",
                                                     "(Ljava/lang/String;Ljava/lang/String;F)Z"
1 Answers

I had this problem with a NoSuchMethodError: no non-static method error of an interface, which occured only in RELEASE build configuration. It helped to add the whole interface with parameter

-keep public class <classname_here>

in the proguard-rules.pro file.

May be something similar is required for a missing static-method.

Related