EnoxSoftware / OpenCVForUnity

OpenCV for Unity (Untiy Asset Plugin)
https://assetstore.unity.com/packages/tools/integration/opencv-for-unity-21088
557 stars 175 forks source link

opencv2.framework not found #193

Open BikalBinodAdhikari opened 3 weeks ago

BikalBinodAdhikari commented 3 weeks ago

While building it from Mac and unity project exported as flutterios I'm getting this kind of error.. I have added opencv2.framework but still it says not found. Can anyone help!! this happened in Mac also in unity I have error after exporting.

Screenshot 2024-08-21 at 9 54 20 PM
EnoxSoftware commented 3 weeks ago

I have not tried exporting to Flutter yet, so I have not checked if OpenCVForUnity works with Flutter.

BikalBinodAdhikari commented 3 weeks ago

can you look into the issue please.. it is very frustrating as my client needs the app as soon as possible. also this might help OpenCV to work in other platforms as well.

EnoxSoftware commented 3 weeks ago

What tools do you use to export from Unity projects to Flutter projects?

BikalBinodAdhikari commented 3 weeks ago

fuw.unitypackage

EnoxSoftware commented 3 weeks ago

I added “/ios/UnityLibrary/Frameworks/OpenCVForUnity/Plugins/iOS/devices/opencv2.framework” as instructed in the official documentation and it worked fine.

https://github.com/juicycleff/flutter-unity-view-widget/tree/master?tab=readme-ov-file

Unity plugins that make use of native code (Vuforia, openCV, etc.) might need to be added to Runner like UnityFramework. Check the contents of the /ios/UnityLibrary/Frameworks/ directory. Any .framework located in (subdirectories of) this directory is a framework that you can add to Runner.

flutter_opencv_add_framework image0
BikalBinodAdhikari commented 2 weeks ago

Still after building from flutter and using it here... it is saying I'm using macOS Sonoma and Xcode latest in Intel Macbook Pro.. I've followed and done everything

ld: framework 'opencv2' not found clang: error: linker command failed with exit code 1 (use -v to see invocation)

and below is my code of OpenCVForUnityIOSBuildPostprocessor.cs

if (UNITY_5 || UNITY_5_3_OR_NEWER) && UNITY_IOS

using UnityEngine; using UnityEditor; using UnityEditor.Callbacks; using UnityEditor.iOS.Xcode; using System.IO; using System.Linq;

namespace OpenCVForUnity { public class OpenCVForUnityIOSBuildPostprocessor : MonoBehaviour { [PostProcessBuild] public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { if (buildTarget == BuildTarget.iOS) { // Simplified framework path handling string opencvFrameworkPath = Directory.GetDirectories(path, "opencv2.framework", SearchOption.AllDirectories).FirstOrDefault(); if (string.IsNullOrEmpty(opencvFrameworkPath)) throw new System.Exception("Can't find opencv2.framework");

            // Set the OpenCV framework to Embedded Binaries and add the framework search path

if UNITY_5_0 || UNITY_5_1 || UNITY5_2

            string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

else

            string projPath = PBXProject.GetPBXProjectPath(path);

endif

            PBXProject proj = new PBXProject();
            proj.ReadFromString(System.IO.File.ReadAllText(projPath));

            // Use the new methods for getting the target GUID

if UNITY_2019_3_OR_NEWER

            string target = proj.GetUnityMainTargetGuid(); // For app target

elif UNITY_2017_2_OR_NEWER

            string target = proj.GetUnityFrameworkTargetGuid(); // For source/plugins target

else

            string target = proj.TargetGuidByName("Unity-iPhone");

endif

            // Add framework search paths
            proj.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks/OpenCVForUnity/Plugins/iOS");

            File.WriteAllText(projPath, proj.WriteToString());

            // Check if the Target minimum iOS Version is set to 9.0 or higher

if UNITY_5_5_OR_NEWER

            string targetVersion = PlayerSettings.iOS.targetOSVersionString;
            int versionNumber;
            if (int.TryParse(targetVersion.Split('.')[0], out versionNumber) && versionNumber < 9)
            {

else

            if ((int)PlayerSettings.iOS.targetOSVersion < (int)iOSTargetOSVersion.iOS_9_0)
            {

endif

                UnityEngine.Debug.LogError("Please set Target minimum iOS Version to 9.0 or higher.");
            }
        }
    }
}

}

endif

Screenshot 2024-08-30 at 12 34 52 AM
EnoxSoftware commented 2 weeks ago

I have successfully built in the following environment. Unity version : 2022.3.21f1 Xcode version : 14.2 OpenCVForUnity version : 2.6.2 flutter version : 3.24.1

I followed the instructions in the Unity project setup on the official site to export the Xcode project, then manually added opencv2.framework to the Xcode project. I then ran the “flutter run” command to build the flutter application.

Also, OpenCVForUnityIOSBuildPostprocessor.cs is only called for Unity's normal build process. If you export your Xcode project with this flutter_unity_widget, you will need to manually add opencv2.framework.