Including shared object library in Android

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.