2

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:enter image description here

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

helloliu
  • 115
  • 3
  • 15

4 Answers4

4

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)
Mable John
  • 4,518
  • 3
  • 22
  • 35
  • I write my `.mk` as you said,which you can see above.But I can not find `*.so`files in the build apk.@mablevj – helloliu Nov 21 '16 at 07:35
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.

Martin
  • 748
  • 7
  • 20
  • 1
    I tried the same thing, but I am unable to see .so file in my final apk after mma command. Can you please help? – tejas Dec 31 '19 at 06:16
  • I agree with tejas, even I cannot see the so file after extracting my final apk after mm. – zeitgeist May 11 '22 at 07:34
0

You can refer Error adding prebuilt apk with shared libraries to AOSP and How to include prebuilt library in Android.bp file? for sample code.

Please note that on doing mm with this change, the apk that is built with not contain the libPrintString.so files. It will be instead be in /system directory of target based on your configuration. So you cannot use the apk directly and instead have to flash a full build.

zeitgeist
  • 852
  • 12
  • 19
0

Best way to add shared library in Android.mk and making sure it will be part of system/lib or system/lib64 based of CPU ARCh is

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := AndroidMediaShell
LOCAL_PRIVILEGED_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := APPS
LOCAL_SRC_FILES := app/$(LOCAL_MODULE).apk
**LOCAL_PREBUILT_JNI_LIBS :=** lib/lib_example.so
**LOCAL_MODULE_TARGET_ARCH :=** arm or arm64 or x86
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_OVERRIDES_PACKAGES :=
include $(BUILD_PREBUILT)
SAURABH_12
  • 2,262
  • 1
  • 19
  • 19