Search code examples
javaandroidandroid-studiojava-native-interface

How to suppress "Cannot resolve corresponding JNI function" in Android Studio?


I am creating a native method in Android Studio which is registered using RegisterNatives in JNI_OnLoad when the library is loaded. The problem is that I want to encrypt the method name and signature strings, but if I do that Android Studio doesn't let me compile the app because of this error: "Cannot resolve corresponding JNI function Java_my_app_Native_initializeApplication." How can I suppress this?


Solution

  • Clicking the quick fix button gave me a pop up to add a @Suppress("KotlinJniMissingFunction") annotation to either the class or the file. You can keep it there or move it to all your methods, eg:

    @Suppress("KotlinJniMissingFunction")
    external fun initializeApplication()
    

    or

    @Suppress("KotlinJniMissingFunction")
    class Native : AppCompatActivity() {
    ...
    }
    

    The equivalent annotation for Java is @SuppressWarnings("JavaJniMissingFunction").