0

I have compiled my project with 'ndk-build' and generated the .so file. when run run application it gives error "No implementation found for native".

when I run it in debug mode, it breaks where the native function is called and eclipes shows this screen-image

I have checked this -link and some other, all my jni functions name are syncronyed.. but not sure where am I going wrong. please help

Update adding some code snipt

MainActivity.java

package com.example.myproject2;


import java.io.InputStream;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

   import java.io.BufferedInputStream;
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.FileNotFoundException;
   import java.io.FilenameFilter;
   import java.io.IOException;
   import java.nio.ByteBuffer;
   import java.nio.ByteOrder;
   import java.util.ArrayList;
   import java.util.HashMap;





public class MainActivity2 extends Activity {



static int bytesize=0;

//public class fRead{






     public native int getMyData(short[] shorts,int size);

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

    ..
..
}

mytest.c code

#include "com_example_myproject2_MainActivity.h"


JNIEXPORT jint JAVA_com_example_myproject2_MainActivity2_getMyData(jshortArray shorts,jint byteArrsize){



int a=0;
int i=0;
int avg=0;


return avg;

}
Community
  • 1
  • 1
MMH
  • 1,676
  • 5
  • 26
  • 43
  • It would be great, if you could post some code. – Saurabh Meshram Sep 16 '14 at 04:19
  • its a simple jni program.. my first jni program.. – MMH Sep 16 '14 at 04:39
  • Is there any reason why the screenshot speaks about **com.myproject2.MainActivity2** while in **mytest.c** you address **com.myproject1.MainActivity** (i.e. `JAVA_com_example_myproject1_MainActivity_getMyData()` vs. expected `JAVA_com_example_myproject2_MainActivity2_getMyData()`? – Alex Cohn Sep 16 '14 at 07:08
  • nothing.... the screenshot is from 2nd test.. with same code.. thanks I will update accordingly – MMH Sep 16 '14 at 07:11

2 Answers2

1

Change your definition of getMyData

jint JAVA_com_example_myproject1_MainActivity_getMyData(jshortArray shorts,jint byteArrsize){

to

JNIEXPORT jint JNICALL Java_com_example_myproject1_MainActivity_getMyData(JNIEnv *env, jobject obj, jshortArray array, jint size)

MainActivity.java

package com.example.myproject1;
/* All imports */ 

public class MainActivity extends Activity {

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

    /* Native Function Declaration */
    public static native int getMyData(short[] shorts, int size);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        getMyData(array, size);    /* Native Function call */
    }
}

main.c

#include <stdio.h>
#include <android/log.h>
#include <jni.h>

#define TAG "HelloJNI"

JNIEXPORT jint JNICALL Java_com_example_myproject1_MainActivity_getMyData(JNIEnv *env, jobject obj, jshortArray array, jint size)
{
    __android_log_print(ANDROID_LOG_DEBUG, TAG, "JNI Function Called : getMyData");
    return size;
}

Output:
When the application is launched.

$ adb logcat -s HelloJNI
D/HelloJNI(  672): JNI Function Called : getMyData

Note:
A word of caution, Avoid having underscore(_) in your Package name, Activity name or JNI function name.

Saurabh Meshram
  • 8,106
  • 3
  • 23
  • 32
  • oh I already changed the definition of getMyData to JNIEXPORT, so that was not a problem – MMH Sep 16 '14 at 05:49
  • Are you also passing `JNIEnv *env, jobject obj,` as first two arguments to `getMyData()`, Also don't forget to add `JNICALL` – Saurabh Meshram Sep 16 '14 at 05:59
0

I have find out what was going wrong with my code. The problem was quit different from the answers in other links so I am posting it here.. so that it can help others.

The problem was in my native function.

rather than calling the function as-

JNIEXPORT jint JAVA_com_example_myproject2_MainActivity2_getMyData(jshortArray shorts,jint{
...
...
}

I should call it as-

JNIEXPORT jint JAVA_com_example_myproject2_MainActivity2_getMyData(JNIEnv* pEnv, jobject 
pThis,jshortArray shorts ,jint byteArrsize){
...
...
}

Even though I am not using JNIEnv* pEnv and jobject pThis I will have to write them in the native side function.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
MMH
  • 1,676
  • 5
  • 26
  • 43