Hi,
I’m having a lot of trouble trying to package an Android app including OpenCV with UE4.21.
I successfully included OpenCV files for Windows 64 and I used it for an in-editor function. But when it comes to Android… ugh.
Here is the error I get when I try to package:
I found several tutos and almost no doc. But everything I got is at most for UE4.17 and not working (it is not even changing the error message a little bit).
Here is my Game.Build.cs (only the OpenCV loading function) :
public bool LoadOpenCV (ReadOnlyTargetRules Target)
{
bool isLibrarySupported = false;
string OpenCVPath = Path.Combine(ThirdPartyPath, "OpenCV");
bool isDebug = Target.Configuration == UnrealTargetConfiguration.Debug;
if (Target.Platform == UnrealTargetPlatform.Win64)
{
PublicLibraryPaths.Add(Path.Combine(OpenCVPath, "Libraries", "Win64"));
PublicAdditionalLibraries.Add("opencv_world410.lib");
isLibrarySupported = true;
}
else if (Target.Platform == UnrealTargetPlatform.Android)
{
bEnableExceptions = true;
bUseRTTI = true;
string SdkBase = Path.Combine(OpenCVPath, "Libraries", "Android", "sdk");
string LibraryPath = Path.Combine(SdkBase, "native", "staticlibs");
PublicIncludePaths.Add(Path.Combine(SdkBase, "native/jni/include"));
PublicLibraryPaths.Add(Path.Combine(LibraryPath, "armeabi-v7a"));
PublicAdditionalLibraries.Add("libopencv_calib3d.a");
PublicAdditionalLibraries.Add("libopencv_core.a");
PublicAdditionalLibraries.Add("libopencv_dnn.a");
PublicAdditionalLibraries.Add("libopencv_features2d.a");
PublicAdditionalLibraries.Add("libopencv_flann.a");
PublicAdditionalLibraries.Add("libopencv_highgui.a");
PublicAdditionalLibraries.Add("libopencv_imgcodecs.a");
PublicAdditionalLibraries.Add("libopencv_imgproc.a");
PublicAdditionalLibraries.Add("libopencv_ml.a");
PublicAdditionalLibraries.Add("libopencv_objdetect.a");
PublicAdditionalLibraries.Add("libopencv_photo.a");
PublicAdditionalLibraries.Add("libopencv_stiching.a");
PublicAdditionalLibraries.Add("libopencv_video.a");
PublicAdditionalLibraries.Add("libopencv_videoio.a");
PublicLibraryPaths.Add(Path.Combine(LibraryPath, "arm64-v8a"));
PublicAdditionalLibraries.Add("libopencv_calib3d.a");
PublicAdditionalLibraries.Add("libopencv_core.a");
PublicAdditionalLibraries.Add("libopencv_dnn.a");
PublicAdditionalLibraries.Add("libopencv_features2d.a");
PublicAdditionalLibraries.Add("libopencv_flann.a");
PublicAdditionalLibraries.Add("libopencv_highgui.a");
PublicAdditionalLibraries.Add("libopencv_imgcodecs.a");
PublicAdditionalLibraries.Add("libopencv_imgproc.a");
PublicAdditionalLibraries.Add("libopencv_ml.a");
PublicAdditionalLibraries.Add("libopencv_objdetect.a");
PublicAdditionalLibraries.Add("libopencv_photo.a");
PublicAdditionalLibraries.Add("libopencv_stiching.a");
PublicAdditionalLibraries.Add("libopencv_video.a");
PublicAdditionalLibraries.Add("libopencv_videoio.a");
LibraryPath = Path.Combine(SdkBase, "native", "libs");
RuntimeDependencies.Add(Path.Combine(LibraryPath, "armeabi-v7a/libopencv_java4.so"));
RuntimeDependencies.Add(Path.Combine(LibraryPath, "arm64-v8a/libopencv_java4.so"));
isLibrarySupported = true;
AdditionalPropertiesForReceipt.Add(new ReceiptProperty("AndroidPlugin", Path.Combine(ModuleDirectory, "RocketFramesAPL.xml")));
}
else
{
string Err = string.Format("{0} dedicated server is made to depend on {1}. We want to avoid this, please correct module dependencies.", Target.Platform.ToString(), this.ToString());
System.Console.WriteLine(Err);
}
if (isLibrarySupported)
{
PublicIncludePaths.AddRange(new string[] { Path.Combine(OpenCVPath, "Includes") });
PublicDelayLoadDLLs.Add("opencv_world410.dll");
PublicDelayLoadDLLs.Add("opencv__ffmpeg410_64.dll");
}
PublicDefinitions.Add(string.Format("WITH_OPENCV_BINDING={0}", isLibrarySupported ? 1 : 0));
return isLibrarySupported;
}
Here is the APL.xml file I attempted to do, but it seems to change nothing:
<?xml version="1.0" encoding="utf-8"?>
<!-- steps to add to build additions -->
<root xmlns:android="http://schemas.android.com/apk/res/android">
<!-- init section is always evaluated once per architecture -->
<init>
<setBool result="bSupported" value="false"/>
<isArch arch="armeabi-v7a">
<setBool result="bSupported" value="true"/>
</isArch>
<isArch arch="arm64-v8a">
<setBool result="bSupported" value="true"/>
</isArch>
</init>
<!-- optional files or directories to copy to Intermediate/Android/APK -->
<resourceCopies>
<isArch arch="armeabi-v7a">
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_calib3d.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_calib3d.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_core.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_core.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_dnn.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_dnn.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_features2d.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_features2d.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_flann.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_flann.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_highgui.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_highgui.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_imgcodecs.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_imgcodecs.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_imgproc.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_imgproc.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_ml.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_ml.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_objdetect.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_objdetect.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_photo.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_photo.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_stiching.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_stiching.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_video.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_video.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/armeabi-v7a/libopencv_videoio.a"
dst="$S(BuildDir)/staticlibs/armeabi-v7a/libopencv_videoio.a" />
<copyFile src="$S(PluginDir)/OpenCV/libs/armeabi-v7a/libopencv_java4.so"
dst="$S(BuildDir)/libs/armeabi-v7a/libopencv_java4.so" />
</isArch>
<isArch arch="arm64-v8a">
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_calib3d.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_calib3d.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_core.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_core.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_dnn.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_dnn.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_features2d.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_features2d.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_flann.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_flann.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_highgui.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_highgui.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_imgcodecs.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_imgcodecs.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_imgproc.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_imgproc.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_ml.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_ml.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_objdetect.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_objdetect.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_photo.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_photo.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_stiching.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_stiching.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_video.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_video.a" />
<copyFile src="$S(PluginDir)/OpenCV/staticlibs/arm64-v8a/libopencv_videoio.a"
dst="$S(BuildDir)/staticlibs/arm64-v8a/libopencv_videoio.a" />
<copyFile src="$S(PluginDir)/OpenCV/libs/arm64-v8a/libopencv_java4.so"
dst="$S(BuildDir)/libs/arm64-v8a/libopencv_java4.so" />
</isArch>
</resourceCopies>
<!-- optional libraries to load in GameActivity.java before libUE4.so -->
<soLoadLibrary>
<if condition="bSupported">
<true>
<loadLibrary name="OpenCV" failmsg="Failed to load OpenCV library" />
</true>
</if>
</soLoadLibrary>
</root>
I really need to do that, it is for work and it is quite urgent I would be immensely grateful to anyone who could help me!
- CraftyWeazel