简体   繁体   中英

Build error while compiling Android source (JNI)

I added some new functionality in C and when I try to build it, it gives me the following error:

libnativehelper/include/nativehelper/JNIHelp.h:116: error: undefined reference to 'jniRegisterNativeMethods' error.

I have included jnihelp.h in my C files.

Is this a makefile related issue or am I missing something?

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE    := newfile
LOCAL_SRC_FILES := newfile.cpp

include $(BUILD_SHARED_LIBRARY)

EDIT 6/5/14: I finally fixed it. Just thought I'd put all the info here in case someone else needs it.

  1. The manifest had to be modified to load certain libraries as mentioned in my comment below.This was to fix the undefined reference to 'jniRegisterNativeMethods' error
  2. The cpp file that had the native implementation had to be inside an extern "C" block. This was causing the UnsatisfiedLinkError.

You need to go to parent folder where you have your build and dalvik binaries. Then from there you need to type:

build yourproj

(replace yourproj with folder you have your codes in it)

I found the issue was indeed in the makefile I looked around for other JNI implementations and added this to the makefile

LOCAL_SHARED_LIBRARIES := \
        libandroid_runtime \
        libandroidfw \
        libnativehelper \
        libRS \
        libcutils \
        libskia \
        libutils

I have no idea what a few of the libraries in there are for, but I left them there and it compiled. Now I have a different issue. I get the 'Unsatified Link error' when I load the compiled library. Does anyone have an idea on this?

Edit: My compiled libraries are being transferred to the phone. I manually pushed them onto the /system/lib directory on the phone but I still get the 'UnsatisfiedLinkError'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM