How to use Android Java .aar library?
I googled this quite a bit, but came out empty handed. There were some links but those related to source code version of UE. Before going down that path I decided to asks here whether there is some simple way to add and access an .aar library in my UE 4.20 Android project?
I found this announcement telling that aar files can be registered e.g. in aar-imports.txt. It continues about gradle files, but it remains a bit unclear whether something more needs to be added there or not. I really wish there were a solid document about using .aar files!
Based on some forum advice, I inserted my lib into aar-imports.txt file, like this
and inserted the lib under C:\NVPACK\android-sdk-windows\extras\m2repository\com\mycompany\myproduct\mylib\mylib-release\1.0\mylib-release-1.0.aar, together with a handmade POM file.
I also added the following lines into gradle.properties file in the Android Studio:
Although I am not sure are these necessary or not.
It seems that this way the file is included into the build. At least the Unreal launch complained over wrong paths until I got them right.
To get forward I should now make AndroidThunkJava_* methods for all my library public static methods, I think.
Should I make a class similar to AndroidJNI.*, except for my own library only? Or should I add my own library methods into AndroidJNI class? And where to put these files (in same place as AndroidJNI or somewhere in my own project structure)?
I solved this by simply pulling the .jar out of the .aar package. .jar works without problems, and luckily I did not need any resources from .aar.
answered Apr 11 '19 at 12:29 PM
If by "simple" you mean without playing with C++ then no, you need to brige code from Java to C++ in order to allow UE4 to use it, or else you use already existing APIs and only modify java portion, but i don't of any library that this would be sufficient.
The Java portion of UE4 is inside /Build/Android you can extend or modify that code by placing extra stuff in your project in that location, so you add aar library same way as you would do in any other andorid project. But thats not enough, in order for that library to be usable in UE4 you need to bind it in C++ and potentially create some blueprint nodes if you want to. For that you need to create extra classes in C++ (you can do that in project or plugin, where no need to modify engine source code), to check how to do it look up AndroidJNI in engine source code:
Follow this question
Once you sign in you will be able to subscribe for any updates here