'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.



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1