Ask Your Question

Linking prebuilt opencv static library in

asked 2019-01-15 12:40:34 -0500

epatton gravatar image

updated 2019-03-22 16:17:59 -0500

Hi I am trying to link prebuilt external/opencv3 libopencv_core.a in the Android tree to my project that's also in the tree. I get the following error

ninja: error: 'out/target/product/neo/obj/STATIC_LIBRARIES/libopencv_core_prebuilt_intermediates/export_includes', needed by 'out/target/product/neo/obj/STATIC_LIBRARIES/libNV_intermediates/import_includes', missing and no known rule to make it

I am able to link to libopencv_core when Android builds it, but I need to link to opencv3 built with opencl created using the following make.

cd /hdd/NEO8/external/opencv3/platforms
cd build_android_arm
make -j8
OpenCV static libraries are created in the lib/arm64-v8a directory.

My project is all native code (c++) with no jni or Java.

The tree structure is:

                external/opencv3  (this is where I build the libopencv_core.a)
                device/my_app  (this is where my is)

The external/opencv3 code is v3.0 downloaded from Google.

I'd attach the but this forum only allows image attachments. Below is how I'm adding the prebuilt to the

include $(CLEAR_VARS)
PREBUILT_PATH := /hdd/NEO8/external/opencv3/platforms/build_android_arm/lib/arm64-v8a
PREBUILT_INCLUDE_PATH := /hdd/NEO8/external/opencv3
    $(PREBUILT_INCLUDE_PATH)/modules/core/include \
    $(PREBUILT_INCLUDE_PATH)/opencv2 \
LOCAL_MODULE            := libopencv_core_prebuilt
LOCAL_SRC_FILES := $(PREBUILT_PATH)/libopencv_core.a

The LOCAL_EXPORT_C_INCLUDE_DIRS is the same as what I use when I link to the Android built opencv3.

I can tell that the Android build process is finding the libopencv_core.a file because when I change the static library name to something bogus, i.e.

LOCAL_SRC_FILES := $(PREBUILT_PATH)/libopencv_core_bogusName.a

the linker says it can't find libopencv_core_bogusName.a.

Is there a way to get more information out of the Android build info like a verbose=true setting? Any ideas on what I can try would be greatly appreciated.

This is the entire

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
PREBUILT_PATH := /hdd/NEO8/external/opencv3/platforms/build_android_arm/lib/arm64-v8a
PREBUILT_INCLUDE_PATH := /hdd/NEO8/external/opencv3

    $(PREBUILT_INCLUDE_PATH)/modules/core/include \
    $(PREBUILT_INCLUDE_PATH)/opencv2 \

LOCAL_MODULE            := libopencv_core_prebuilt
LOCAL_SRC_FILES := $(PREBUILT_PATH)/libopencv_core.a


include $(CLEAR_VARS)

LOCAL_MODULE        := libNV
LOCAL_MODULE_TAGS   := optional

        external/opencv3/include/opencv \
        external/opencv3/include \
        external/opencv3/modules/core/include \
        external/opencv3/modules/hal/include \
        external/opencv3/modules/imgproc/include \
        external/opencv3/modules/photo/include \
        external/opencv3/modules/video/include \
        external/opencv3/modules/objdetect/include \
        external/opencv3/modules/features2d/include \
        external/opencv3/modules/flann/include \
        external/opencv3/modules/calib3d/include \
        external/opencv3/modules/imgcodecs/include \
        external/opencv3/modules/videoio/include \
        external/opencv3/modules/highgui/include \
        external/opencv3/modules/ml/include \
        external/opencv3/modules/shape/include \
        external/opencv3/modules/stitching/include \
        external/opencv3/modules/superres/include \
        external/opencv3/modules/videostab/include \
        external/jsoncpp/include \
        device/my_app/apps/external/OpenCL \
        $(LOCAL_PATH)/include \


                src/NVOpencv.cpp \
                src/NVProcAngles.cpp \
                src/NVUtils.cpp \

        -std=c++14 \
        -fPIC \
        -fsigned-char \
        -frtti \
        -fexceptions \
        -Wno-non-virtual-dtor \
        -Wno-unused-parameter \

        libopencv_hal \

        libc++ \
        libopencv_imgproc ...
edit retag flag offensive close merge delete


This isn't a solution, but an interesting discovery. There is an example in the Android tree at


that follows the instructions at

that also gives the same error as I get when built

ninja: error: 'out/target/product/neo/obj/SHARED_LIBRARIES/foo-prebuilt_intermediates/export_includes', needed by 'out/target/product/neo/obj/SHARED_LIBRARIES/foo-user_intermediates/import_includes', missing and no known rule to make it 08:50:08 ninja failed with: exit status 1 make: * [run_soong_ui] Error 1

epatton gravatar imageepatton ( 2019-01-21 10:58:21 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-03-05 11:44:10 -0500

epatton gravatar image

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)


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/
  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 export BUILD_FOO=1 mm
  5. mkdir lib lib64 cp $OUT/system/lib/ lib/ cp $OUT/system/lib64/ lib64/
  6. Rename to ("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 into a Android.bp, there are tools that can do this for you. i.e. "androidmk > Android.bp"


subname = "Android.bp"

build = [

subdirs = [

optional_subdirs = [

And the Android.bp

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

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",
edit flag offensive delete link more


Update: Since external/opencv3 is built on, my Android.bp cannot see it's libraries. Apparently this is a known issue. Consequently I'm forced to using an in my project yet have not figured out a way to get it to work.

epatton gravatar imageepatton ( 2019-03-22 16:20:32 -0500 )edit

Question Tools

1 follower


Asked: 2019-01-15 12:40:34 -0500

Seen: 1,683 times

Last updated: Mar 22 '19