SoFunction
Updated on 2025-04-09

Perfectly solve the problem that the Android jni project will delete other so files

In Android project development, JNI development is used in the project, and I wrote my own So library in C/C++. Debugging and running everything is normal, and the file code is as follows:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE:=observer
LOCAL_SRC_FILES:=
LOCAL_C_INCLUDES:= $(LOCAL_PATH)/include
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)

If we need to introduce other third-party so libraries into libs/armeabi, when the project is compiled and run, we will find that the third-party so library that has just been added has been deleted.

In this case, you only need to adjust as follows:

1. Create a new directory "prebuilt" in jni (of course, it is OK to call it other names)

2. Modify the file and add our third-party so library. The content added to me is as follows:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := tpnsSecurity
LOCAL_SRC_FILES := prebuilt/
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := tpnsWatchdog
LOCAL_SRC_FILES := prebuilt/
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE:=observer
LOCAL_SRC_FILES:=
LOCAL_C_INCLUDES:= $(LOCAL_PATH)/include
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)

The above article perfectly solves the problem that the Android JN project will delete other So files is all the content I share with you. I hope it can give you a reference and I hope you can support me more.