javaandroidjava-native-interface.so

I use .so library and get NoSuchMethodError error


I use .so library, as this

package ru.integrics.mobileschool.view.activity;

import android.util.Base64;

public class MainActivity {

    public MainActivity(){
        System.loadLibrary("x2");
    }
    public native String x01(String str);
    public String get(String str){
        String key = Base64.encodeToString(x01(str.substring(0, str.length() / 2)).getBytes(), Base64.NO_WRAP);
        return key;
    }

}

But i get error:

JNI DETECTED ERROR IN APPLICATION: 
JNI CallObjectMethodV called with pending exception java.lang.NoSuchMethodError: 
no non-static method "Lru/integrics/mobileschool/view/activity/MainActivity;.getPackageManager()Landroid/content/pm/PackageManager;"

I tried set methods static, but not working


Solution

  • If you read the error you see it is complaining about a missing Java method because your MainActivity class does not inherit from the android.app.Activity class, which provides the required getPackageManager method.