开发者

Help regarding Android NDK

I am a beginner in using Android NDK.

I am using Eclipse and I installed cygwin to build the c file to generate the .so file

But while building the c file in cygwin I am always getting the error

make: ***No rule to make target 'file.c' ... .Stop

I tried building different C codes but for every file it says the same error ..

Here is the source code:

public class ndktest extends Activity 
{
 static {   
    System.loadLibrary("ndkt");   
   }
 private native void helloLog(String logThis);  
 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    helloLog("this is to test log file");
 }   }

file.c

void Java_com_ndktest_helloLog(JNIEnv * env, jobject this, jstring logThis)

{

jboolean isCopy;

const char * szLogThis = (*env)->GetStringUTFChars(env, logThis, &isCopy);

(*env)->ReleaseStringUTFChars(env, logThis, szLogThis);

}

And here is my Android.mk

LOCAL_PATH := $(call my-dir)   
include $(CLEAR_VARS)   
LOCAL_LDLIBS := -llog   
LOCAL_MODULE    := ndkt 
L开发者_StackOverflowOCAL_SRC_FILES := file.c
include $(BUILD_SHARED_LIBRARY)  

I searched for the solution for the cause of error ... but nothing works for me.

Can anyone tell me where I am making the mistake ?

Thanks,

Siva Kumar


Most likely the error lies in any of the following two areas:

  1. In the function name you have used. See if your package name matches with the function name you have used in the C code. Java_com_ndktest_helloLog

  2. Verify that the Android.mk file is setting up the right directory to find the C source file in the jni directory.

This is a great site, to setup your first ndk program. Very easy to follow and also contains screenshots: http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/


For your java.lang.UnsatisfiedLinkError, you need to find out what the full message is.

You'll see the exception at

Runtime.loadLibrary(String, ClassLoader) line: 434  

If you step past that, you'll get to

ExceptionInInitializerError.<init>(Throwable) line: 59  

Now you can see the contents of the exception, and it'll look something like:

java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1311]: 1281 cannot locate 'somethingInterestingWouldBeHere'...

And that should help figure out what's wrong.

Keep in mind that you have to manually figure out the load order for your libraries; if library A depends on library B, you need to load B, then A. That doesn't happen automatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜