[opencv4:android]: Correct paths in portfile#11269
Closed
pthom wants to merge 1 commit intomicrosoft:masterfrom
Closed
[opencv4:android]: Correct paths in portfile#11269pthom wants to merge 1 commit intomicrosoft:masterfrom
pthom wants to merge 1 commit intomicrosoft:masterfrom
Conversation
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
````
Contributor
|
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 |
Contributor
Author
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the pull request
This PR handles installation issues for opencv4 under android, by arranging some paths in the package folder.
What does your PR fix? Fixes issue [opencv4:android] build failure (folder /include is empty or not present) #11229
Which triplets are supported/not supported?
Android triplets
Have you updated the CI baseline?
No
Does your PR follow the maintainer guide?
Yes
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:
vcpkg complains about a missing include folder, and about the presence
of unwanted README.android file.
Steps to reproduce the error
You can copy-paste the script below to populate them (and maybe later adjust them to your needs):
Install android ndk
Set ANDROID_NDK_HOME env variable, for example:
You will get the following error
What this patch does
It reorganizes the package folder post install, so that it contents looks like:
How to test this patch
You will get the following prefab structure