Problem linking OpenCV to Unity/Android App (Android Studio)

Hi.

I have problems getting OpenCV to run on my Android smartphone, when using OpenCV as part of an externalNativeBuild in Android.

Overall, OpenCV is integrated into a Unity application, retrieving camera images, calling the OpenCV plugin (c++) and then displaying the images plus some Texts on the Android phone.
I believe that the unity part works: it compiles without errors and includes the OpenCV into the apk.

When creating the Android plugin with Android Studio, I am successfully including the OpenCV module into a very simple project module. Thus far, the module consists of a simple function
extern “C” {
int info_FeatureFinderLib() {
return 20;
}
}
The module compiles, including OpenCV properly (as reported in the “Build” log).

Some details from the configuration files:

  • build.gradle(both app FeatureFinderLib and openCV):
    compileSdk 33, minSdk 28, targetSdk 33
  • CMakeLists.txt:
    set(OpenCVDIR C:/opencv-4.5.5-android-sdk/OpenCV-android-sdk/sdk/native/jni)
    find_package(OpenCV 4.5 REQUIRED java)

As said, the system compiles and builds. It includes three files in the aar for arm64-v8a and armeabi-v7a:

  • libFeatureFinderLib.so
  • liblog.so
  • libopencv_java4.so
    But when I execute it, it is not able to execute “info_FeatureFinderLib()”.
    It generates the following error message in Logcat:
    DllNotFoundException: FeatureFinderLib assembly: type: member:(null)
    at (wrapper managed-to-native) FeatureFinderScript.info_FeatureFinderLib()
    at FeatureFinderScript.Update() …

If, however, I remove the line "find_package(OpenCV 4.5 REQUIRED java) from CMakeLists.txt, the app is able to execute “info_FeatureFinderLib()”.

I thus conclude that the overall setup (Unity - Android - cpp) works. I just cannot find/link to the OpenCV package.

Software:
OpenCV 4.5.5,
Android Studio Flamingo 2022.2.1,
Unity 2022.3.3f1
HW:
Samsung Note 8 (Android Api level 28),
Google Pixel 2 (Api level 30)

Can you please give me some hints what I need to change in order to correctly link to OpenCV ?

Thanks
-Gundi.