5

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.

Vijeth PO
  • 400
  • 1
  • 2
  • 19

2 Answers2

14

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,
        },
    }
Beta
  • 96,650
  • 16
  • 149
  • 150
Vijeth PO
  • 400
  • 1
  • 2
  • 19
  • 1
    Thanks for this answer, I dive this issue serveral hours. This one is the correct final solution. :) – liuyang1 Sep 07 '18 at 01:44
  • 1
    However above libraries are so formats files. Can I use jar files in the same way? – Gary Chen Oct 12 '20 at 16:04
  • 1
    Hey I have a similar issue can you please have a look https://stackoverflow.com/questions/65718113/aosp-building-application-with-jni-libs – Viktor Apoyan Jan 14 '21 at 11:59
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.

zeitgeist
  • 852
  • 12
  • 19
  • 1
    I am doing a similar job and I confirm that the apks generates doesn't contain the .so file. This means we can never replace it. Is there a way to overcome this issue? – user1638466 Aug 24 '23 at 09:28