What is correct and present method of packaging a prebuilt shared library (.so) for Android
While there are replies on this topic historically, they tend to be several years old and definitely not in keeping with the modern way (4.11 at the time of this post) UE deploys custom libraries on Android.
So I would like to know: what is the correct, modern (per our present version of UE) method of packaging prebuilt shared libraries for android such that we can call into them from our GameActivity.Java?
I know that the answer is not modifying private engine source and creating a custom build (that is what a lot of posts outline). I doubt that I need to modify the .MK files for unreal (the present architecture uses things like GameActiivityInsert.XML and such to create changes in the manifest and elsewhere). And I see all kinds of methods all over the place in terms of where to put one's .so binaries ranging from a plugin to a number of other places.
Here is a simple scenario to answer:
I have a library for android, compiled as arm7 called libsimplelibrary.so. It has a function called AddTwo that adds two floats.
1) Where exactly should this binary sit in the file/directory structure a newly generated Unreal project? 2) what files, specifically, do I need to modify to inform UE4 that this file exists and needs to part of my APK? GameActivityInsert.XML I would think, and our build.cs. But would like to see and understand the bare minimum necessary here. 3) What UE files need to be modified to load this library. I see a section in gameActivityInsert.XML. Do I add it there? And if so, what is the syntax?
Bonus: 4) how do I call into the library and call the Add function. GameActicityInsert.XML again I would think, but can I simply declare the C function in the shared library as a"native" in the java and call into it? or do I need to craft a JNI call by hand?
(I know there are many posts on this, but they are several years old and either 1) involve modifying a custom build of the ue4 engine or 2) suggest "look at what ", but we are not developing a plugin. I am really hoping for the "hello world"/simplest demonstration of this.)
asked Apr 27 '16 at 10:16 PM in Packaging & Deployment
The proper way to do this since 4.10 is to use AndroidPluginLanguage. During packaging, all the APL XML files registered with the build system (in the module Build.cs files) are run to allow copying of resources, modify the AndroidManfest.xml and proguard files, and insert code into GameActivity.java. While APL was intended for plugins, any module may register a XML file to process, so you can just have a code based project and add to its Build.cs, for example.
The above is an example. The My_APL.xml is expected to be placed in the same directory as the Build.cs (PluginPath).
You can find an example in GearVR_APL.xml. It does some conditional staging of libraries and modifications to the manifest, proguard, and GameActivity.java. is the section you would want to copy your .so into place for packaging. is where your .so would be loaded. Since this is just native code, you can just call it from your C++ code. You only need to use JNI to call back and forth between native C++ and Java code.
answered May 03 '16 at 05:47 PM
Chris Babcock STAFF
Follow this question
Once you sign in you will be able to subscribe for any updates here