将本地库从android应用程序移动到系统lib并从应用程序访问

将本地库从android应用程序移动到系统lib并从应用程序访问

本文介绍了将本地库从android应用程序移动到系统lib并从应用程序访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用android ndk编译了一个本机代码.现在,而不是将该库保留为.apk的一部分,我想将其安装在android系统(system/lib64)中,并从系统加载我的应用程序.我将库推送到system/lib64,并从android应用程序的lib文件夹中删除了库.但是当我尝试运行时,我会得到

I have compiled one native code with android ndk. Now instead of keeping that library as part of .apk i want install it in android system (system/lib64) and my application load from system. I pushed the library to the system/lib64 and deleted the libraries from the android application's lib folder. But when i try to run i am getting

"java.lang.UnsatisfiedLinkError: dlopen failed: library "something.so" not found"

以下是我的makefile文件

Following is my makefile

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := eng
LOCAL_C_INCLUDES += $(LOCAL_PATH) $(LOCAL_PATH)/Include
LOCAL_SRC_FILES := ABCProtocol/ABCProtocol.c ABCProtocol/DatalinkLayer.c ABCProtocol/PhysicalLayer.c
LOCAL_MODULE := libABCXYZProtocol
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := eng
LOCAL_C_INCLUDES += $(LOCAL_PATH) $(LOCAL_PATH)/$(KERNEL_DIR)/include $(LOCAL_PATH)/Include $(LOCAL_PATH)/Util $(LOCAL_PATH)/Include/Linux/XYZ $(LOCAL_PATH)/ABCProtocol
LOCAL_SRC_FILES := Linux/XYZ/ABCXYZLinux.c Util/Util.c Util/Logger.c
#LOCAL_CFLAGS += -Wno-error=format-security
LOCAL_CFLAGS += -w
LOCAL_MODULE := libABCXYZWrapper
LOCAL_SHARED_LIBRARIES :=libABCXYZProtocol
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE:=com_example_reader_ABCXYZappnote_NativeLibrary
LOCAL_SRC_FILES:=com_example_reader_ABCXYZappnote_NativeLibrary.c
LOCAL_C_INCLUDES += $(LOCAL_PATH) $(LOCAL_PATH)/$(KERNEL_DIR)/include $(LOCAL_PATH)/Include $(LOCAL_PATH)/Util $(LOCAL_PATH)/Include/Linux/XYZ
#LOCAL_CFLAGS += -DANDROID
LOCAL_SHARED_LIBRARIES:=libc libABCXYZWrapper libABCXYZProtocol
include $(BUILD_SHARED_LIBRARY)

推荐答案

不允许应用程序从系统库位置访问非公共API: https://developer.android.com/about/versions/nougat/android-7.0-changes.html#ndk .您的应用程序使用的库必须与您的应用程序打包在一起.

Applications are not allowed to access non-public APIs from system library locations: https://developer.android.com/about/versions/nougat/android-7.0-changes.html#ndk. Libraries used by your app must be packaged with your app.

您为什么仍要将它们放在/system/lib中?

Why do you want to put them in /system/lib anyway?

这篇关于将本地库从android应用程序移动到系统lib并从应用程序访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 03:17