Including shared object library in Android

Hi, I have a .so library that I wish to include in the project during runtime. I include it the same way as .a static library. However, at the beginning of the gameplay, it says library not found on the path C:/… (path on my c library). However, if I write the path for my Android device, it tells me it fails to compile becuase it doesn’t find the library during compiling time. Thanks

Hi FrankKappaPride,

I need some more information to help you here. I’m assuming you are trying to link to your .so during compile so it will load it at runtime on the device as a dependency?

If so, you want to use PublicAdditionalLibraries.Add() with a path to your .so if the TargetPlatform == UnrealTargetPlatform.Android in the Build.cs. You will also need to copy the .so for packaging by having an APL XML file. You can do something like this:


if (Target.Platform == UnrealTargetPlatform.Android)
{
	string BuildPath = Utils.MakePathRelativeTo(ModuleDirectory, BuildConfiguration.RelativeEnginePath);
	AdditionalPropertiesForReceipt.Add(new ReceiptProperty("AndroidPlugin", Path.Combine(BuildPath, "My_APL.xml")));

 	PublicAdditionalLibraries.Add(BuildPath + "/armv7/libmyso.so");
}

Then in your My_APL.xml:


<?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>
	</init>

	<!-- optional files or directories to copy to Intermediate/Android/APK -->
	<resourceCopies>
		<isArch arch="armeabi-v7a">
			<copyFile src="$S(PluginDir)/armv7/libmyso.so"
						dst="$S(BuildDir)/libs/armeabi-v7a/libmyso.so" />
		</isArch>
	</resourceCopies>

	<!-- optional libraries to load in GameActivity.java before libUE4.so -->
	<soLoadLibrary>
		<if condition="bSupported">
			<true>
				<loadLibrary name="myso" failmsg="Failed to load myso library" />
			</true>
		</if>
	</soLoadLibrary>
</root>


Put the XML file in the same directory as the Build.cs and your libmyso.so in an armv7 subdirectory.

Sorry for the late reply! But thanks to you I was able to get python(both compiler and other library) working in Gear VR! Just a minor detail, PublicAdditionalLibraries.Add(BuildPath + “/armv7/libmyso.so”);
this line seems to be pointing to a wrong directory. My engine is somewhere in Documents, my project is on desktop, however it tells me it doesnt find the so file at C:/Documents/Desktop/…/libmyso.so