NDK编译多个库 [英] NDK compiling multiple libraries

查看:192
本文介绍了NDK编译多个库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的原生code。在我的Andr​​oid应用程序。首先,我只用一个库。所以,一切正常。但现在我有一个多库集成到它。我不知道什么应该是我的项目的JNI文件夹中的理想结构(如在何处放置整个code等)。我发现周围的工作。我创建了内部JNI .IE LIBRARY1和library2两个文件夹。再创建一个文件夹JNI这两个文件夹内,并放置相应的code。在文件夹中。

我得到它的编译。正在生成两个.so文件,但我无法使用它在我的应用程序。我不能用的System.loadLibrary(library1.so)加载库;也试过提供完整路径。但失败。

另外,我不知道到父JNI文件夹的Andr​​oid.mk文件里面写的是什么。

目前的结构: project_folder - > JNI - > LIBRARY1 - > JNI - >源$ C ​​$ C的Andr​​oid.mk这里写 project_folder - > JNI - > library2 - > JNI - >源$ C ​​$ C的Andr​​oid.mk这里写

更新#1:

  GDBSERVER:[臂的Linux androideabi-4.6]库/ armeabi / gdbserver的
Gdbsetup:库/ armeabi / gdb.setup
使:***没有规则,使目标`JNI / ZAP / JNI / ZAP / ZAP / error.c',需要'OBJ /本地/ armeabi / OBJ文件调试/ ZAP / JNI / ZAP / ZAP / error.o 。停止。
 

我不使用Application.mk。 这是我的Andr​​oid.mk:

  TOP_PATH:= $(叫我-DIR)

#编译库1
包括$(CLEAR_VARS)
LOCAL_PATH:= $(TOP_PATH)/ ZAP
LOCAL_MODULE:=扎普
LOCAL_C_INCLUDES:= $(LOCAL_PATH)/ ZAP
LOCAL_SRC_FILES:= $(LOCAL_PATH)/zap/error.c \
$(LOCAL_PATH)/zap/hello-jni.c \
$(LOCAL_PATH)/zap/zap.c \
$(LOCAL_PATH)/zap/zapd.c \
$(LOCAL_PATH)/zap/zaplib.c
包括$(BUILD_SHARED_LIBRARY)
 

解决方案

我已经找到了最好的结构是使用JNI /文件夹只有NDK-建立makefile和外界保持源在自己的文件夹。这是很容易添加到现有的项目没有在JNI重组你的树。

不过,你必须要小心你如何处理LOCAL_PATH变量和使用$(叫我-DIR)。这里有一个工作的例子:

  • 在MyProject的/
    • LIBRARY1 /
      • source1.cpp
    • library2 /
      • source2.cpp
    • 在JNI /
      • Android.mk
      • Application.mk

Android.mk:

 #TOP_PATH指的是项目的根目录(MyProject的)
TOP_PATH:= $(叫我-DIR)/ ..

#编译库1
包括$(CLEAR_VARS)
LOCAL_PATH:= $(TOP_PATH)/ LIBRARY1
LOCAL_MODULE:= LIBRARY1
LOCAL_C_INCLUDES:= $(LOCAL_PATH)
LOCAL_SRC_FILES:= source1.cpp
包括$(BUILD_SHARED_LIBRARY)

#编译库2
包括$(CLEAR_VARS)
LOCAL_PATH:= $(TOP_PATH)/ library2
LOCAL_MODULE:= library2
LOCAL_C_INCLUDES:= $(LOCAL_PATH)
LOCAL_SRC_FILES:= source2.cpp
包括$(BUILD_SHARED_LIBRARY)
 

您可以随意拆分出来在Android.mk的部分,以自己的makefile文件。

I am using native code in my android app. Firstly I was only using one library. So everything worked fine. But now I have to integrate one more library into it. I've no idea what should be the ideal structure of the jni folder of my project (as in where to place the entire code, etc.). I found a work around. I created two folders inside jni .i.e library1 and library2. Again created a jni folder inside both the folders and placed respective code in the folders.

I got it to compile. Both .so files are being generated, but I am unable to use it in my application. I cant load the library using System.loadLibrary("library1.so"); Also tried providing full path. But failed

Also I have no idea what to write inside the parent jni folder's Android.mk file.

Current structure: project_folder -> jni -> library1 -> jni -> "source code" an Android.mk is written here project_folder -> jni -> library2 -> jni -> "source code" an Android.mk is written here

UPDATE #1 :

Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
make: *** No rule to make target `jni/zap/jni/zap/zap/error.c', needed by `obj/local/armeabi/objs-debug/zap/jni/zap/zap/error.o'.  Stop.

I am not using Application.mk. This is my Android.mk:

TOP_PATH := $(call my-dir)

# Build library 1
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/zap
LOCAL_MODULE := zap
LOCAL_C_INCLUDES := $(LOCAL_PATH)/zap
LOCAL_SRC_FILES := $(LOCAL_PATH)/zap/error.c \
$(LOCAL_PATH)/zap/hello-jni.c \
$(LOCAL_PATH)/zap/zap.c \
$(LOCAL_PATH)/zap/zapd.c \
$(LOCAL_PATH)/zap/zaplib.c 
include $(BUILD_SHARED_LIBRARY)

解决方案

The best structure I've found is to use the jni/ folder for ndk-build makefiles only, and keep the source outside in their own folders. This is easy to add to existing projects without restructuring your tree under jni.

However, you do have to be careful about how you handle the LOCAL_PATH variable and use of $(call my-dir). Here's a working example:

  • MyProject/
    • library1/
      • source1.cpp
    • library2/
      • source2.cpp
    • jni/
      • Android.mk
      • Application.mk

Android.mk:

# TOP_PATH refers to the project root dir (MyProject)
TOP_PATH := $(call my-dir)/..

# Build library 1
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/library1
LOCAL_MODULE := library1
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := source1.cpp
include $(BUILD_SHARED_LIBRARY)

# Build library 2
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/library2
LOCAL_MODULE := library2
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := source2.cpp
include $(BUILD_SHARED_LIBRARY)

You can optionally split out the sections in Android.mk to their own makefiles.

这篇关于NDK编译多个库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆