0

I Pasted .so file into my new project folder

jniLibs->arm64-v8a  
jniLibs->armeabi-v7a

Inside MainActivity.java file I declared

static {
        System.loadLibrary("filename");
    }

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView textView = findViewById(R.id.textView);
        try {
           textView.setText(METHODNAME("string")+"");
        } catch (Exception e) {
           Log.i("error", e.message());
        }
    }

public static native int[] METHODNAME(String strng);

When I run the app it shows below error

java.lang.UnsatisfiedLinkError: No implementation found for int[] com.android.myapp.MainActivity.METHODNAME(java.lang.String)
botagi
  • 1
  • 2
  • You need to initialize METHODNAME. Currently it is undefined. – Mahendra Gunawardena Jun 01 '20 at 12:02
  • in the end i initialized as `public static native int[] METHODNAME(String strng);` – botagi Jun 01 '20 at 12:03
  • What you have is a declaration? You need to assign a value such as space or string. – Mahendra Gunawardena Jun 01 '20 at 12:06
  • Oh just noticed that you have an `int[]`. What is the purpose for the `int[]` – Mahendra Gunawardena Jun 01 '20 at 12:15
  • `Is it saying that it is unable to find METHODNAME() inside .so file?` Im trying to call the method which is inside .so file and im printing it inside textview. Im new to this and i cant find any proper tuts too. – botagi Jun 01 '20 at 12:15
  • So you want to display a value inside the text view correct, – Mahendra Gunawardena Jun 01 '20 at 12:18
  • yes! which is the return value from METHODNAME() inside .so file – botagi Jun 01 '20 at 12:20
  • How about in your onCreate method initialize `String hello;` and then do something like ` hello="This is my first project";` to test out your code. – Mahendra Gunawardena Jun 01 '20 at 12:25
  • i think we are not on the same page. It is NDK project which i need to execute c code inside java(onCreate) using JNI. For this to work i am doing any thing wrong from my side? – botagi Jun 01 '20 at 12:32
  • Sorry for my misunderstanding. I suggest that you update the body of question describe the problem. SO has a lot of experts that can help you. Good Luck. – Mahendra Gunawardena Jun 01 '20 at 12:47
  • What does the C++ function corresponding to `METHODNAME` look like? You will need something like `extern "C" JNIEXPORT jintArray JNICALL Java_com_android_myapp_MainActivity_METHODNAME(JNIEnv *env, jobject thiz) {}` in your C++ source that generates the .so library. – tgeng Jun 26 '20 at 06:19

0 Answers0