skip to Main Content

I want to run OpenCV with flutter. First of all , i try to the FFI library to bind to native code.

Flutter Dev says " On iOS, you need to tell Xcode to statically link the file:

In Xcode, open Runner.xcworkspace.
Add the C/C++/Objective-C/Swift source files to the Xcode project "

But i don’t have a file name that ‘ Runner.xcworkspace "

My XCode Folder

My AndroidStudio Folder

Its very hard to run opencv or c++ code in Flutter. I am working on it for 3 days and there is no improvement.

2

Answers


  1. If you followed the guide on flutter.dev Binding to native code using dart:ffi it is because you created a plugin template and as such the iOS folder only contains plugin-specific files.
    To find the iOS folder you are looking for, please open the "example" folder that was also created when you made the project and open the iOS folder therein.

    Login or Signup to reply.
  2. for run OpenCV with flutter and with native code using ffi, you can do with this way:

    iOS: in Podfile add next line to target

    pod 'OpenCV', '~> 4.3'
    

    In Build Settings -> Library Search Paths add recursive path

    "$(SRCROOT)/Pods/OpenCV"
    

    For debug running you can add opencv.framework to your project directory

    Android: for android you have two methods

    1. native: donwloading SDK for Android (.java extensions) like most tutorials on google…
    2. c compiled: folder android/app/build.gradle add next parts
        android {
            ...
            defaultConfig {
                ...
                externalNativeBuild {
                            cmake {
                                // Enabling exceptions, RTTI
                                // And setting C++ standard version
                                cppFlags '-frtti -fexceptions -std=c++11'
                
                                // Shared runtime for shared libraries
                                arguments "-DANDROID_STL=c++_shared"
                            }
                        }
                ...
            }
            ...
            //external c++ plugin
            externalNativeBuild{
                cmake{
                    path "<pathtoyour>/CMakeLists.txt"
                }
            }
            ...
        }
    

    File CMakeList.txt

    cmake_minimum_required(VERSION 3.4.1) 
    
    set( OpenCV_DIR "<path>/OpenCV-android-sdk/sdk/native/jni" )
    find_package( OpenCV REQUIRED )
    message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")
    
    add_library( <youe binary> SHARED <path to your c++ or c file> )
    target_link_libraries( <youe binary> ${OpenCV_LIBS} )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search