how to add some third party *.so files in Android.mk?

懵懂的女人 提交于 2020-06-25 06:11:31

问题


I am compiling my own app in AOSP,and I want to add my own app in package/app in AOSP. I have some *.sofiles which will be used in my app,but how to write Android.mkabout to use these third party .sofiles?here is my Android.mk:

  LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
  LOCAL_MODULE_TAGS := optional
  LOCAL_SHARED_LIBRARIES :=myprebuilt
  LOCAL_STATIC_JAVA_LIBRARIES :=OrbbecJar
  LOCAL_SRC_FILES := $(call all-java-files-under, src)\
               $(call all-java-files-under, openCVLibrary2410/src)\
               openCVLibrary2410/src/main/aidl/org/opencv/engine/OpenCVEngineInterface.aidl
  LOCAL_RESOURCE_DIR:= $(LOCAL_PATH)/openCVLibrary2410/res\
                  $(LOCAL_PATH)/res
   LOCAL_CERTIFICATE := platform
   LOCAL_PACKAGE_NAME := HelloWorld
   include $(BUILD_PACKAGE)
    ##################################################
   include $(CLEAR_VARS)
   LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := OrbbecJar:OrbbecSDKPro_161114_v1.1.2.jar
   include $(BUILD_MULTI_PREBUILT)
   include $(CLEAR_VARS)
   LOCAL_MODULE:=myprebuilt
   LOCAL_SRC_FILES:=libs/armeabi-v7a/libHWWrapper.so\
                     libs/armeabi-v7a/libXnDeviceSensorV2.so\
                     libs/armeabi-v7a/libXnFormats.so
    include $(PREBUILT_SHARED_LIBRARY)
   # Use the folloing include to make our test apk.
  include $(call all-makefiles-under,$(LOCAL_PATH))

The build apk contents shows:

but I cant find*.so`files in my build apk


回答1:


You must declare each prebuilt library you use as a single independent module. To do so, perform the following steps:

  1. Give the module a name. This name does not need to be the same as that of the prebuilt library, itself.
  2. In the module's Android.mk file, assign to LOCAL_SRC_FILES the path to the prebuilt library you are providing
  3. Include PREBUILT_SHARED_LIBRARY or PREBUILT_STATIC_LIBRARY, depending on whether you are using a shared (.so) or static (.a) library.

For more details about Declaring a Prebuilt Library

Example

# How to fetch the ssl_static lib
include $(CLEAR_VARS) 
LOCAL_MODULE := ssl_static
LOCAL_SRC_FILES := <folder_path>/libssl_static.a
include $(PREBUILT_STATIC_LIBRARY)

# shared library
include $(CLEAR_VARS)
LOCAL_MODULE := HWWrapper
LOCAL_SRC_FILES := <folder_path>/libHWWrapper.so
include $(PREBUILT_SHARED_LIBRARY)



回答2:


The solution by @mablevj works if you have prebuilt static libraries (those with the .a extension). For shared libraries (.so extension), you need to define each .so, because you can't combine all three .so files into one .so file.

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

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

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

Then it will show up in your final .apk. You should also put these three definitions in a separate file to keep things clean, but it is not required.



来源:https://stackoverflow.com/questions/40712837/how-to-add-some-third-party-so-files-in-android-mk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!