Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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 – 重用arm共享库全部内容,希望文章能够帮你解决android – 重用arm共享库所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。