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]: Correct paths in portfile #11269

Closed
wants to merge 1 commit into from

Conversation

pthom
Copy link
Contributor

@pthom pthom commented May 9, 2020

Describe the pull request

This PR handles installation issues for opencv4 under android, by arranging some paths in the package folder.


Additional details

Note: Beware, I am new to the android platform, and I did not succeed in trying out the resulting opencv4 package on an android application ("find_package(OpenCV)" fails).
May be @atkawa7 could help with some instructions on this: below I explain how I can succesfully export a prefab package. My issue is that I do not know how to consume it in an android app

Current status of opencv4 under android

Currently the compilation of opencv4 for android leads to
the following folder structure:

packages/opencv4_arm_android/
    debug/
    lib/
    sdk/
         native/
             jni/
                 include/
                     opencv2/
    share/
    README.android

vcpkg complains about a missing include folder, and about the presence
of unwanted README.android file.

Steps to reproduce the error

  1. Install the android triplets:

You can copy-paste the script below to populate them (and maybe later adjust them to your needs):

echo "
set(VCPKG_TARGET_ARCHITECTURE arm)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
" > triplets/community/arm-android.cmake

echo "
set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
" > triplets/community/arm64-android.cmake

echo "
set(VCPKG_TARGET_ARCHITECTURE x86)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
" > triplets/community/x86-android.cmake

echo "
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
" > triplets/community/x64-android.cmake
  1. Install android ndk

  2. Set ANDROID_NDK_HOME env variable, for example:

export ANDROID_NDK_HOME=/home/YourAccount/Android/Sdk/ndk-bundle
  1. Try to build opencv4[core]:
./vcpkg install "opencv4[core]:arm-android"

You will get the following error

-- Installing: .../vcpkg/packages/opencv4_arm-android/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_arm-android:

    .../vcpkg/packages/opencv4_arm-android/README.android

Files cannot be present in those directories.

The following files are placed in
.../vcpkg/packages/opencv4_arm-android/debug:

    .../vcpkg/packages/opencv4_arm-android/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

What this patch does

It reorganizes the package folder post install, so that it contents looks like:

packages/opencv4_arm-android
├── debug
│   ├── lib
│   └── sdk
│       └── native
├── include
│   └── opencv2
│       ├── calib3d
│       ├── core
│       └── ...
├── lib
└── share
    ├── opencv
    │   ├── abi-armeabi-v7a
    │   └── licenses
    └── opencv4

How to test this patch

  1. Build opencv for all 4 archs
./vcpkg install "opencv4[core]:arm-android" "opencv4[core]:arm64-android" "opencv4[core]:x64-android" "opencv4[core]:x86-android"
  1. Export opencv4 prefab:
 ./vcpkg export --triplet x64-android "opencv4[core]" --prefab

You will get the following prefab structure

prefabo/opencv4
├── aar
│   ├── AndroidManifest.xml
│   ├── META-INF
│   │   └── LICENSE
│   └── prefab
│       ├── modules
│       │   ├── opencv_calib3d
│       │   │   ├── libs
│       │   │   │   ├── android.arm64-v8a
│       │   │   │   │   ├── abi.json
│       │   │   │   │   ├── include
│       │   │   │   │   │   └── opencv2
│       │   │   │   │   └── libopencv_calib3d.so
│       │   │   │   ├── android.armeabi-v7a
│       │   │   │   │   ├── abi.json
│       │   │   │   │   ├── include
│       │   │   │   │   │   └── opencv2
│       │   │   │   │   └── libopencv_calib3d.so
│       │   │   │   ├── android.x86
│       │   │   │   │   ├── abi.json
│       │   │   │   │   ├── include
│       │   │   │   │   │   └── opencv2
│       │   │   │   │   └── libopencv_calib3d.so
│       │   │   │   └── android.x86_64
│       │   │   │       ├── abi.json
│       │   │   │       ├── include
│       │   │   │       │   └── opencv2
│       │   │   │       └── libopencv_calib3d.so
│       │   │   └── module.json
│       │   ├── opencv_core
│       │   │   ├── libs
│       │   │   │   ├── android.arm64-v8a
│       │   │   │   │   ├── abi.json
│       │   │   │   │   ├── include
│       │   │   │   │   │   └── opencv2
│       │   │   │   │   └── libopencv_core.so

Currently the compilation of opencv4 for android leads to
the following folder structure:

````
packages/opencv4_arm_android/
    debug/
    lib/
    sdk/
         native/
             jni/
                 include/
                     opencv2/
    share/
    README.android
````

vcpkg complains about a missing include folder, and about the presence
of unwanted README.android file.

**Steps to reproduce the error**
********************************

1. Install the android triplets:

You can copy-paste the script below to populate them (and maybe later adjust them to your needs):

````
echo "
set(VCPKG_TARGET_ARCHITECTURE arm)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
" > triplets/community/arm-android.cmake

echo "
set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
" > triplets/community/arm64-android.cmake

echo "
set(VCPKG_TARGET_ARCHITECTURE x86)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
" > triplets/community/x86-android.cmake

echo "
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
" > triplets/community/x64-android.cmake
````

2. Install [android ndk](https://developer.android.com/ndk/downloads/)

3. Set ANDROID_NDK_HOME env variable, for example:
````
export ANDROID_NDK_HOME=/home/YourAccount/Android/Sdk/ndk-bundle
````

4. Try to build opencv4[core]:
````
./vcpkg install "opencv4[core]:arm-android"
````

You will get the following error
````
-- Installing: .../vcpkg/packages/opencv4_arm-android/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_arm-android:

    .../vcpkg/packages/opencv4_arm-android/README.android

Files cannot be present in those directories.

The following files are placed in
.../vcpkg/packages/opencv4_arm-android/debug:

    .../vcpkg/packages/opencv4_arm-android/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
````

**What this patch does**
************************

It reorganizes the package folder post install, so that it contents looks like:

````
packages/opencv4_arm-android
├── debug
│   ├── lib
│   └── sdk
│       └── native
├── include
│   └── opencv2
│       ├── calib3d
│       ├── core
│       └── ...
├── lib
└── share
    ├── opencv
    │   ├── abi-armeabi-v7a
    │   └── licenses
    └── opencv4
````

**How to test this patch**
**************************

1. Build opencv for all 4 archs

````
./vcpkg install "opencv4[core]:arm-android" "opencv4[core]:arm64-android" "opencv4[core]:x64-android" "opencv4[core]:x86-android"
````

2. Export opencv4 prefab:

````
 ./vcpkg export --triplet x64-android "opencv4[core]" --prefab
````

You will get the following prefab structure
````
prefabo/opencv4
├── aar
│   ├── AndroidManifest.xml
│   ├── META-INF
│   │   └── LICENSE
│   └── prefab
│       ├── modules
│       │   ├── opencv_calib3d
│       │   │   ├── libs
│       │   │   │   ├── android.arm64-v8a
│       │   │   │   │   ├── abi.json
│       │   │   │   │   ├── include
│       │   │   │   │   │   └── opencv2
│       │   │   │   │   └── libopencv_calib3d.so
│       │   │   │   ├── android.armeabi-v7a
│       │   │   │   │   ├── abi.json
│       │   │   │   │   ├── include
│       │   │   │   │   │   └── opencv2
│       │   │   │   │   └── libopencv_calib3d.so
│       │   │   │   ├── android.x86
│       │   │   │   │   ├── abi.json
│       │   │   │   │   ├── include
│       │   │   │   │   │   └── opencv2
│       │   │   │   │   └── libopencv_calib3d.so
│       │   │   │   └── android.x86_64
│       │   │   │       ├── abi.json
│       │   │   │       ├── include
│       │   │   │       │   └── opencv2
│       │   │   │       └── libopencv_calib3d.so
│       │   │   └── module.json
│       │   ├── opencv_core
│       │   │   ├── libs
│       │   │   │   ├── android.arm64-v8a
│       │   │   │   │   ├── abi.json
│       │   │   │   │   ├── include
│       │   │   │   │   │   └── opencv2
│       │   │   │   │   └── libopencv_core.so
````
@cenit
Copy link
Contributor

cenit commented May 9, 2020

In general, renaming files after build is the source of many problems when consuming the library in a downstream project

Can you please try my pr with opencv 4.3 update, #11130? It might solve the include issue for android toolchain

@pthom
Copy link
Contributor Author

pthom commented May 9, 2020

In general, renaming files after build is the source of many problems when consuming the library in a downstream project

Can you please try my pr with opencv 4.3 update, #11130? It might solve the include issue for android toolchain

Many thanks for this informed answer!

Your PR seems to do quite a lot to solve the issue, expect for the remaining README.android files.
I will close my PR and add a comment to yours.

@pthom pthom closed this May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants