Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't setup Android properly #107

Open
lucasxas opened this issue Mar 25, 2024 · 1 comment
Open

Can't setup Android properly #107

lucasxas opened this issue Mar 25, 2024 · 1 comment

Comments

@lucasxas
Copy link

Hi friends, I bumped into this project just the other day as I was thinking about ways to make OpenCV smaller in an app that I maintain.

The problem is that I have zero experience with CMake or JNI at all, so the instructions provided in the Readme file aren't sufficent for me.

I have extracted the zip file into my projects src/main/jni. Also created the CMakeLists (that I never had) and added the configuration you provided in the readme, but saw a couple of problems and with some searching I ended up with this:

project(camera)

cmake_minimum_required(VERSION 3.22.1)

set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.9.0-android/sdk/native/jni)
find_package(OpenCV REQUIRED)

target_link_libraries(camera ${OpenCV_LIBS})

It still doesn't work, but it now complains that

  Cannot specify link libraries for target "camera" which is not built by
  this project.```
  
  Can anyone offer me a little help? Appreciated! :) 
@phaiminh
Copy link

phaiminh commented Mar 27, 2024

you can follow my cmake file here:

cmake_minimum_required(VERSION 3.4.1)
set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.9.0-android/sdk/native/jni)
find_package(OpenCV REQUIRED)
if(OpenCV_FOUND)
    message("OpenCV found successfully")
    include_directories(${OpenCV_INCLUDE_DIRS})
    # Link against OpenCV libraries
   # target_link_libraries(your_target_library ${OpenCV_LIBRARIES})
else()
    message(FATAL_ERROR "OpenCV not found")
endif()
add_library( # Sets the name of the library.
        native_lib

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        ../cpp/native_lib.cpp) 

# Link your library with OpenCV
target_link_libraries(native_lib ${OpenCV_LIBS})

native_lib.cpp is the c++ file that imports openCV and does things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants