Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include prebuilt library in Android.bp file?

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.

like image 391
Vijeth PO Avatar asked Feb 02 '18 08:02

Vijeth PO


2 Answers

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,
        },
    }
like image 126
Vijeth PO Avatar answered Oct 03 '22 04:10

Vijeth PO


Here is an example how to do it.

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

java_import {
    name: "stringutils",
    jars: ["libs/stringutils.jar"],
    sdk_version: "current",
}

android_app {
    name: "HelloWorld",
    manifest: "AndroidManifest.xml",
    srcs: ["src/**/*.java",],
    sdk_version: "current",
    resource_dirs: [
      "res/",
    ],
    static_libs: [
        "com.google.android.material_material",
        "androidx-constraintlayout_constraintlayout",
        "stringutils",
    ],
    jni_libs: ["libPrintString"],
    certificate: "platform",
    privileged: true,
    platform_apis: true,
    optimize: {
      enabled: false,
    },
    dex_preopt: {
      enabled: false,
    },
}

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.

like image 36
zeitgeist Avatar answered Oct 03 '22 02:10

zeitgeist