Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opencv4:android] build failure (folder /include is empty or not present) #11229

Closed
pthom opened this issue May 7, 2020 · 2 comments
Closed
Assignees
Labels
category:port-bug The issue is with a library, which is something the port should already support

Comments

@pthom
Copy link
Contributor

pthom commented May 7, 2020

When building opencv4 for android, the compilation and "cmake install" steps succeed.
However, after this, vcpkg will complain that "The folder /include is empty or not present".

This seems to be due to the fact that opencv emits a non standard include folder hierarchy: see below.

Host Environment

  • Host OS: Linux, ubuntu 18.04
  • Target OS: Android armeabi-v7a
  • Compiler: android-ndk / May 2020

To Reproduce

  1. Cherry-pick a PR that fixes an issue for protobuf under android: [protobuf] Correct protobuf under android (Fix issue #8218) #11228

(I submitted this PR a few minutes ago)

  1. Use this triplet file:

triplets/android-armeabi-v7a.cmake

set(VCPKG_TARGET_ARCHITECTURE arm)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)

set(ANDROID_NDK_HOME $ENV{ANDROID_NDK_HOME})
if ("${ANDROID_NDK_HOME}" MATCHES "^$")
  message(FATAL_ERROR 
    "Please set an env variable ANDROID_NDK_HOME pointing to your ndk-bundle folder. 
    For example: export ANDROID_NDK_HOME=/home/your-account/Android/Sdk/ndk-bundle")
endif()
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake)

set(ANDROID_ABI armeabi-v7a)
# ANDROID_ABI can be : "armeabi-v7a" , "armeabi-v7a with NEON", "arm64-v8a", "x86" or "x86_64"
  1. Download and install the android ndk-bundle

  2. Set an env var to the ndk-bundle folder

export ANDROID_NDK_HOME=/home/your-account/Android/Sdk/ndk-bundle
  1. Build the opencv4 package
./vcpkg install "opencv4[core]:android-armeabi-v7a"

Failure logs

-- Installing: .../vcpkg/packages/opencv4_android-armeabi-v7a/share/opencv4/copyright
-- Performing post-build validation
The folder /include is empty or not present. This indicates the library was not correctly installed.
The following files are placed in
.../vcpkg/packages/opencv4_android-armeabi-v7a:

    .../vcpkg/packages/opencv4_android-armeabi-v7a/README.android

Files cannot be present in those directories.

The following files are placed in
.../vcpkg/packages/opencv4_android-armeabi-v7a/debug:

    .../vcpkg/packages/opencv4_android-armeabi-v7a/debug/README.android

Files cannot be present in those directories.

Found 3 error(s). Please correct the portfile:
    ../vcpkg/ports/opencv4/portfile.cmake
-- Performing post-build validation done
Error: Building package opencv4:android-armeabi-v7a failed with: POST_BUILD_CHECKS_FAILED

-Cut and past the appropriate build messages from the console output.
-Please attach any additional failure logs mentioned in the console output.

Additional context

Please note that this issue can only be reproduced after applying a patch on protobuf package for android

@pthom pthom added the category:port-bug The issue is with a library, which is something the port should already support label May 7, 2020
@pthom
Copy link
Contributor Author

pthom commented May 7, 2020

I have a possible patch, like this:

diff --git a/ports/opencv4/portfile.cmake b/ports/opencv4/portfile.cmake
index 95c4c53dc..e918daa09 100644
--- a/ports/opencv4/portfile.cmake
+++ b/ports/opencv4/portfile.cmake
@@ -389,4 +389,11 @@ file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/setup_vars_opencv4.cmd)
 file(REMOVE ${CURRENT_PACKAGES_DIR}/LICENSE)
 file(REMOVE ${CURRENT_PACKAGES_DIR}/debug/LICENSE)
 
+if(${VCPKG_CMAKE_SYSTEM_NAME} STREQUAL "Android")
+  file(RENAME ${CURRENT_PACKAGES_DIR}/sdk/native/jni/include ${CURRENT_PACKAGES_DIR}/include)
+  file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/sdk)
+  file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/README.android)
+  file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/README.android)
+endif()
+
 file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)

But I do not know if it makes sense: all it does is reorganize the package folder content after opencv installation. vcpkg seems to be happy after this and the installation succeeds.

Does my patch make sense ?


Remark: with my patch, there is a naming issue (which might be unrelated): the advice given by vcpkg for use in cmake list reads:

    find_package(abi-armeabi-v7a CONFIG REQUIRED)

instead of

    find_package(opencv4 CONFIG REQUIRED)
./vcpkg install "opencv4[core]:android-armeabi-v7a"
Computing installation plan...
The following packages will be built and installed:
    opencv4[core]:android-armeabi-v7a
Starting package 1/1: opencv4:android-armeabi-v7a
Building package opencv4[core]:android-armeabi-v7a...
-- Using cached /home/pascal/dvp/vcpkg/downloads/opencv-opencv-4.1.1.tar.gz
-- Using source at /home/pascal/dvp/vcpkg/buildtrees/opencv4/src/4.1.1-fb9e10326a
-- Configuring android-armeabi-v7a-dbg
-- Configuring android-armeabi-v7a-rel
-- Building android-armeabi-v7a-dbg
-- Building android-armeabi-v7a-rel
-- Installing: /home/pascal/dvp/vcpkg/packages/opencv4_android-armeabi-v7a/share/opencv4/copyright
-- Performing post-build validation
-- Performing post-build validation done
Building package opencv4[core]:android-armeabi-v7a... done
Installing package opencv4[core]:android-armeabi-v7a...
Installing package opencv4[core]:android-armeabi-v7a... done
Elapsed time for package opencv4:android-armeabi-v7a: 17.27 s

Total elapsed time: 17.27 s

The package opencv4:android-armeabi-v7a provides CMake targets:

    find_package(abi-armeabi-v7a CONFIG REQUIRED)
    # Note: 9 target(s) were omitted.
    target_link_libraries(main PRIVATE opencv_ml opencv_core opencv_flann opencv_photo)

@pthom
Copy link
Contributor Author

pthom commented May 9, 2020

I'm closing this issue, since there is an ongoing port of opencv4.3 in which I explained some possible adaptations here: #11130 (comment)

@pthom pthom closed this as completed May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-bug The issue is with a library, which is something the port should already support
Projects
None yet
Development

No branches or pull requests

2 participants