How to include prebuilt library in Android.bp file?

15,966

After some struggle here I found the solution

1) There is a tool called androidmk to generate Android.bp file out of Android.mk file

Use below commands to build androidmk tool

source build/envsetup.sh
    m -j blueprint_tools
Output Path: out/soong/host/linux-x86/bin/androidmk (depending on your host)    

Write normal Android.mk file for prebuilt library like this

include $(CLEAR_VARS)
    LOCAL_MODULE := newlib
    LOCAL_SRC_FILES := newlib.so
    LOCAL_MODULE_SUFFIX := .so
    LOCAL_MODULE_CLASS := SHARED_LIBRARIES
    LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)
    LOCAL_MODULE_TAGS := optional
    include $(BUILD_PREBUILT)

Now run below command androidmk Android.mk > Android.bp Android.bp file will be created as below

cc_prebuilt_library_shared {
        name: "newlib",
        srcs: ["newlib.so"],

        //ANDROIDMK TRANSLATION ERROR: unspported assignment to LOCAL_MODULE_PATH
        //LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARY)
    }

2) Now using above Android.bp file I got below error

**out/target/product/mytest/symbols/system/lib64/newlib.so: no symbols**

So I added this

strip: {
    none:true,
}

3) Now with new Android.bp I still got this error

**error: newlib.so incompatible target** 

So I added this (created 2 directories lib and lib64 with corresponding libraries)

 target: {
        android_arm: {
            srcs: ["lib/newlib.so"],
        },
        android_arm64: {
            srcs: ["lib64/newlib.so"],
        }
  },

So finally with below Android.bp file my requirement got satisfied

cc_prebuilt_library_shared {
        name: "newlib",
        target: {
            android_arm: {
                srcs: ["lib/newlib.so"],
            },
            android_arm64: {
                srcs: ["lib64/newlib.so"],
            },
        },
        strip: {
            none:true,
        },
    }
Share:
15,966

Related videos on Youtube

Vijeth PO
Author by

Vijeth PO

Interested in Linux Audio (ALSA/codec/I2S/I2C), Android Audio (framework/HAL), Device Drivers

Updated on June 04, 2022

Comments

  • Vijeth PO
    Vijeth PO almost 2 years

    I am using Android-O, and I see most of the .mk files are being replaced by .bp file. Now I have modified one of the source code under hardware/interfaces which is built using .bp files.

    Now i have a prebuilt shared library that is used by the source code.

    But I have not able to figure out how to include prebuilt library into Android.bp file.

    Any help/comments will be really appreciated.

  • liuyang1
    liuyang1 over 5 years
    Thanks for this answer, I dive this issue serveral hours. This one is the correct final solution. :)
  • Gary Chen
    Gary Chen over 3 years
    However above libraries are so formats files. Can I use jar files in the same way?
  • Viktor Apoyan
    Viktor Apoyan over 3 years
    Hey I have a similar issue can you please have a look stackoverflow.com/questions/65718113/…