Skip to content

Problems with adding OpenCV to Android Studio project #24663

@AleksandrPanov

Description

@AleksandrPanov

System Information

Tested with several OpenCV versions:

Brief information

We have to use code fixes to include OpenCV to Android Studio project. Adding OpenCV should work without code fixes.
You could use this guide or https://medium.com/@ankitsachan/android-studio-kotlin-open-cv-16d75f8d9969 to import OpenCV.

Detailed description

Error1

Need add this code to MyApplication/opencv/build.gradle (fix from this):

plugins {
    id 'org.jetbrains.kotlin.android' version '1.7.10'
}

Otherwise, this error will occur:

image

error1.txt

Error2

Need add this code to MyApplication/opencv/build.gradle (fix from this):

    buildFeatures{
        aidl true
        buildConfig true
    }

Otherwise, this error will occur:

image
error3.txt

These errors were reproduced there:

Steps to reproduce

Build OpenCV for Android:

export ANDROID_NDK_HOME=/home/alexander/Android/Sdk/ndk/18.1.5063045/
export ANDROID_SDK=/home/alexander/Android/Sdk/
export ANDROID_NDK_HOME=/home/alexander/Android/Sdk/ndk/18.1.5063045/
python /home/alexander/all/opencv/opencv/platforms/android/build_sdk.py /home/alexander/all/opencv/opencv/build_2/ /home/alexander/all/opencv/opencv --ndk_path /home/alexander/Android/Sdk/ndk/18.1.5063045/ --sdk_path /home/alexander/Android/Sdk/ --config /home/alexander/all/opencv/opencv/platforms/android/ndk-18-api-level-21.config.py

or download OpenCV Android sdk from OpenCV Releases
and add OpenCV to empty Android Studio project.
image

You could use this guide to add OpenCV.

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions