3

I have been trying to include .so library as part of my app in AOSP. It can be done with Android.mk. Below is Android.mk of my application in pacakges/app directory :

 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS)

 LOCAL_MODULE_TAGS := optional

 LOCAL_SRC_FILES := $(call all-java-files-under, src)

 LOCAL_PACKAGE_NAME := OpentokSample  
 LOCAL_CERTIFICATE:= platform

 LOCAL_JNI_SHARED_LIBRARIES=libopentok

 include $(BUILD_PACKAGE)

 include $(call all-makefiles-under,$(LOCAL_PATH))

And below is Android.mk to include libopentok.so :

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libopentok
LOCAL_PREBUILT_LIBS := opentok.so
include $(BUILD_SHARED_LIBRARY)

But this doesn't help ?

user1885618
  • 91
  • 1
  • 2
  • 4
  • Please refer https://stackoverflow.com/questions/14687287/error-adding-prebuilt-apk-with-shared-libraries-to-aosp – zeitgeist May 12 '22 at 12:10

2 Answers2

2

I think that you should use include $(BUILD_PREBUILT) if you use prebuilt .so files, and mark them as LOCAL_MODULE_CLASS := SHARED_LIBRARIES. And you need to list dependencies in LOCAL_REQUIRED_MODULES.

Here goes a sample Android.mk which adds a precompiled apk application and places its .so libraries into system lib folder:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_MODULE := MyApp

LOCAL_CERTIFICATE := platform

LOCAL_REQUIRED_MODULES := libamrcodec libecies

LOCAL_SRC_FILES := MyApp.apk

LOCAL_MODULE_CLASS := APPS

LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)

include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := libamrcodec
LOCAL_SRC_FILES := libs/armeabi/libamrcodec.so
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_PRELINK_MODULE := false
#LOCAL_MODULE_PATH := system/lib
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := libecies
LOCAL_SRC_FILES := libs/armeabi/libecies.so
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_PRELINK_MODULE := false
#LOCAL_MODULE_PATH := system/lib
include $(BUILD_PREBUILT)
Mixaz
  • 4,068
  • 1
  • 29
  • 55
  • What is different with http://stackoverflow.com/a/17470099/421467 ? (Copy libs with PRODUCT_COPY_FILES keyword in device.mk) – Dr.jacky Nov 08 '16 at 11:05
  • I think the difference is that the apk file is handled by AOSP build script as a module with dependencies. You probably can get the same results with PRODUCT_COPY_FILES without modules... – Mixaz Nov 08 '16 at 18:38
  • Will this copy the .so files into the lib folder of apk? – tejas Dec 23 '19 at 10:31
  • @tejas - no, it will copy .so files to system libraries folder, `/system/lib` I think. System apk files do not use local lib folder (in the app folder) as far as I know, in contrary with user apk files – Mixaz Dec 23 '19 at 22:30
  • @Mixaz I have imported a .aar library as a dependency to my system app project. This internally has dependency on some .so files. But these files when built successfully are not being part of apk file. Any leads how to solve this? I have tried almost all possible solutions suggested in the web. Any leads would be much appreciated, here is my post for the same.... https://stackoverflow.com/questions/59452477/how-to-add-so-file-in-android-mk-file/59463047#59463047 – tejas Dec 25 '19 at 04:21
-1
LOCAL_MODULE_TAGS := samples

or

LOCAL_MODULE_TAGS := tests