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

**URL:** <https://forum.opencv.org/t/problem-linking-opencv-to-unity-android-app-android-studio/13862>\
**Category:** Android/Java\
**Created:** [July 14, 2023, 1:17pm UTC](https://forum.opencv.org/t/problem-linking-opencv-to-unity-android-app-android-studio/13862 "2023-07-14T13:17:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gundi](https://avatars.discourse-cdn.com/v4/letter/g/45deac/32.png) [@gundi](https://forum.opencv.org/u/gundi)\
**Post date:** [July 14, 2023, 1:17pm UTC](https://forum.opencv.org/t/problem-linking-opencv-to-unity-android-app-android-studio/13862/1 "2023-07-14T13:17:01Z")

</div>

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.
