I trying to build my first Expo Module (I really love the API so far!) and I have a somewhat unique use case that seems to be outside the scope of the available documentation.
I am trying to wrap OpenCV to provide access to some of its image processing. So far, I have read through the Expo Modules API documentation and this seems to be the most relevant tutorial: https://docs.expo.dev/modules/third-party-library/
However, this guide only seems to explain how to wrap remote third-party libraries that can be added through the implementation
declaration in the build.gradle
file and the s.dependency
declaration in the .podspec
files for Android and iOS respectively.
However, OpenCV is only available as a local module that must be downloaded and imported as a local module. So far, I have only been able to try to add it to the Android version, but I keep getting the same error:
Could not resolve project :opencv.
Required by:
project :app > project :expo > project :expo-opencv
> No matching configuration of project :opencv was found.
It seems like the main issue is that the OpenCV SDK is not getting correctly added as a dependency to the Expo Module.
Any thoughts?
-
I created an Expo Module using these instructions: https://docs.expo.dev/modules/get-started/#creating-a-new-module-with-an-example-project
-
I downloaded the OpenCV SDK for Android from this link: https://opencv.org/releases/
-
I followed these directions which are commented-out at the top of the
OpenCV-android-sdk/sdk/build.gradle
file. They describe how to import the OpenCV module and link it as a dependency.
//
// Notes about integration OpenCV into existed Android Studio application project are below (application 'app' module should exist).
//
// This file is located in <OpenCV-android-sdk>/sdk directory (near 'etc', 'java', 'native' subdirectories)
//
// Add module into Android Studio application project:
//
// - Android Studio way:
// (will copy almost all OpenCV Android SDK into your project, ~200Mb)
//
// Import module: Menu -> "File" -> "New" -> "Module" -> "Import Gradle project":
// Source directory: select this "sdk" directory
// Module name: ":opencv"
//
// - or attach library module from OpenCV Android SDK
// (without copying into application project directory, allow to share the same module between projects)
//
// Edit "settings.gradle" and add these lines:
//
// def opencvsdk='<path_to_opencv_android_sdk_rootdir>'
// // You can put declaration above into gradle.properties file instead (including file in HOME directory),
// // but without 'def' and apostrophe symbols ('): opencvsdk=<path_to_opencv_android_sdk_rootdir>
// include ':opencv'
// project(':opencv').projectDir = new File(opencvsdk + '/sdk')
//
//
//
// Add dependency into application module:
//
// - Android Studio way:
// "Open Module Settings" (F4) -> "Dependencies" tab
//
// - or add "project(':opencv')" dependency into app/build.gradle:
//
// dependencies {
// implementation fileTree(dir: 'libs', include: ['*.jar'])
// ...
// implementation project(':opencv')
// }
//
//
//
Unfortunately, I still get the error described above.