简体   繁体   English

编译Android源(JNI)时生成错误

[英]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: 我在C中添加了一些新功能,当我尝试构建它时,它给了我以下错误:

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

I have included jnihelp.h in my C files. 我已经在我的C文件中包含jnihelp.h

Is this a makefile related issue or am I missing something? 这是与Makefile相关的问题,还是我缺少什么?

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. 编辑6/5/14:我终于解决了它。 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 如下面我的评论中所述,必须修改清单以加载某些库。这是为了修复undefined reference to 'jniRegisterNativeMethods'错误的undefined reference to 'jniRegisterNativeMethods'
  2. The cpp file that had the native implementation had to be inside an extern "C" block. 具有本地实现的cpp文件必须位于extern "C"块内。 This was causing the UnsatisfiedLinkError. 这导致了UnsatisfiedLinkError。

You need to go to parent folder where you have your build and dalvik binaries. 您需要转到具有构建和dalvik二进制文件的父文件夹。 Then from there you need to type: 然后从那里输入:

build yourproj

(replace yourproj with folder you have your codes in it) (将yourproj替换为其中包含代码的文件夹)

I found the issue was indeed in the makefile I looked around for other JNI implementations and added this to the makefile 我发现问题确实存在于我寻找其他JNI实现的生成文件中,并将其添加到生成文件中

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'. 我手动将它们推到电话上的/ system / lib目录中,但仍然出现“ UnsatisfiedLinkError”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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