Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This is a possible solution using Android.bp (the Soong replacement for the Andoird make based built system). It works for the example found in the Android tree at (android-8.1.0_r52)

development/ndk/tests/prebuilt-library/jni

Now when typing "mm" i.e.

android-8.1.0_r52/development/ndk/tests/prebuilt-library/jni$ mm

The prebuilt shared libraries are linked and their export includes are found. Here are the steps (I'm in the process of trying this with my opencv project):

  1. android-8.1.0_r52/$ . build/envsetup.sh
  2. android-8.1.0_r52/$ lunch -> select #29 bullhead
  3. cd development/ndk/tests/prebuilt-library/jni
  4. Build 32-bit and 64-bit foo.so(s) export BUILD_FOO=1 mm
  5. mkdir lib lib64 cp $OUT/system/lib/foo.so lib/libfoo.so cp $OUT/system/lib64/foo.so lib64/libfoo.so
  6. Rename Android.mk to Android.mk.bu ("bu" for backup)
  7. Replace the $(gettop)/Android.bp with the Android.bp-top below (rename to Android.bp)
    • or simply add this line to the existing Android.bp: "development/ndk/tests/prebuilt-library/jni",
  8. Copy attached Android.bp to development/ndk/tests/prebuilt-library/jni
  9. mm

The steps above result in a native executable in a foo-user_exe in bullhead/system/bin/

Although this means I have to rewrite my existing Android.mk into a Android.bp, there are tools that can do this for you. i.e. "androidmk Android.mk > Android.bp"

Android.bp-top

subname = "Android.bp"

build = [
    "build/blueprint/Blueprints",
]

subdirs = [
    "build/soong",
]

optional_subdirs = [
    "art",
    "bionic",
    "bootable/recovery",
    "build/kati",
    "build/tools/*",
    "dalvik",
    "development/*",
    "development/ndk/tests/prebuilt-library/jni",
    "device/*/*",
    "external/*",
    "frameworks/*",
    "frameworks/compile/*",
    "frameworks/hardware/interfaces",
    "frameworks/opt/net/wifi",
    "hardware/*",
    "libcore",
    "libnativehelper",
    "packages/apps/*",
    "prebuilts/clang/host/linux-x86",
    "prebuilts/ndk",
    "prebuilts/sdk",
    "system/*",
    "system/hardware/interfaces",
    "system/tools/*",
    "test/vts",
    "test/vts-testcase/*",
    "vendor/*/*",
]

And the Android.bp

cc_prebuilt_library_shared {
    name: "libfoo",
    vendor: true,
    compile_multilib: "both",
    export_include_dirs: ["foo"],
    target: {
        android_arm: {
            srcs: ["lib/libfoo.so"],
        },
        android_arm64: {
            srcs: ["lib64/libfoo.so"],
        },
    },
    strip: {
        none:true,
    },
}

cc_library_shared {
    name: "foo-user",
    srcs: ["foo-user.c"],
    shared_libs: ["libfoo"],
}

cc_binary {
    name: "foo-user_exe",
    srcs: ["foo-user.c"],
    shared_libs: ["libfoo"],
    stl: "none",
}