android – 重用arm共享库

我已经建立了arm arm共享库(libtest.so).我有兴趣重用一个函数(没有很多依赖项 – 它只创建类实例并调用两个方法).我想调用该函数(它需要一个std :: string参数)并获得返回值.

有可能做这样的事吗?我没有任何头文件.

我试过这个Android.mk,我把libtest.so放在/ jni和/ libs / armeabi,/ lib / armeabi中.此时我的cpp文件编译,但现在是什么?如果可能,我如何从libtest.so调用函数?我从objdump知道它的名字

LOCAL_PATH := $(call my-dir)

 include $(CLEAR_VARS)
 LOCAL_MODULE:= libtest
 LOCAL_SRC_FILES := libtest.so
 include $(PREBUILT_SHARED_LIBRARY)


 include $(CLEAR_VARS)
 LOCAL_MODULE    := hello-jni
 LOCAL_SRC_FILES := hello-jni.cpp
 LOCAL_SHARED_LIBRARIES := libtest
 include $(BUILD_SHARED_LIBRARY)

编辑:

我试图用这个android.mk从hello-jni示例中添加prebuild库:

include $(CLEAR_VARS)
LOCAL_MODULE:= libhello-jni
LOCAL_SRC_FILES := libhello-jni.so
include $(PREBUILT_SHARED_LIBRARY)

它工作,但libtest.so相同的代码显示以下错误(启动时)

UnsatisfiedLinkError: Cannot load libtest.so: FindLibrary returned null

libtest.so存在于libhello-jni.so旁边的文件夹中(在/ data / data / [package] / lib上的设备上).可能有什么不对?

解决方法

我有一个应用程序,我做了类似于你需要的东西(或者你可能正是你需要的东西).

>我有* .so文件形式的预编译库. (例如lib1.so,lib2.so等),
它带有一些标题.
>我创建了一个模块,它通过包含头文件和* .so文件来利用预编译库.在示例中,我将其称为“libtestwrapper”.该模块定义了自己的源文件,并可选择包含.如下所述,可以为第二个模块导出模块功能(如果提供头文件).
>我创建了第二个模块(newModule),它将第一个模块(libtestwrapper)添加到’LOCAL_SHARED_LIBRARIES’中.这使得先前导出的头文件(在’libtestwrapper’中)可用于’newModule’.

这是我的Android.mk的内容:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := libtestwrapper
LOCAL_SRC_FILES := libtestUsage.c # Use the methods of libtest.h here
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include # This is where libtest.h should be

# provide this line if you intend to export any header files to another module
#LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/include # you may also use a different directory than 'include'

LOCAL_LDLIBS := -L$(LOCAL_PATH)/dir_with_libtest_so -libtest # -llog etc.
                                #optionally add any as needed: -llog -ljnigraphics -lz -ldl -lgcc
                                # '-libtest' corresponds to 'libtest.so' - the names must match
                                # -llog is for logcat for example
include $(BUILD_SHARED_LIBRARY)

# Optional:
# Define a second module wich is making use of the first one (i.e. libtestwrapper)
include $(CLEAR_VARS)
LOCAL_MODULE := newModule # this module will be making use of the first one (if needed)
                    # Add local source files. If the files are stored in directories
                    # you have to provide a relative path  starting inside the 'jni' directory.
                    # The example is for this structure: jni/dirToSourceFiles1/*.cpp
LOCAL_SRC_FILES := dirToSourceFiles1/SourceFile1.cpp dirToSourceFiles1/SourceFile2.cpp
LOCAL_C_INCLUDES += $(LOCAL_PATH)/newModule_include # path where the headers of this module are stored
LOCAL_SHARED_LIBRARIES += libtestwrapper # make use of the previous module

# Optionally add this line if any other libs should be used
#LOCAL_LDLIBS := -llog -ljnigraphics -lz -ldl -lgcc
include $(BUILD_SHARED_LIBRARY)

相关文章

Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...
Android实现自定义带文字和图片的Button 在Android开发中经常...
Android 关于长按back键退出应用程序的实现最近在做一个Andr...
android自带的时间选择器只能精确到分,但是对于某些应用要求...