Adding custom files to the Android content


I’m currently implementing a third party library to the UE4. The library itself is already implemented and it’s initializing but to the proper work it needs a path to the file (the certificate, precisely).

On Windows it’s easy, I’m just putting the file into the MyProject\Content directory and then I’m getting the path using:

FString FullCAPath = FPaths::GameContentDir() + "/ca.pem";

But when I’m trying to add this file to the Android apk, or iOS ipa… well, I’m lost here. The builder is not packing all files from the Content folder. How should it be done?

Open packaging settings for your project and add your folder containing your cert file in non-asset folders to package list.

That was it, thanks :slight_smile:

But I have few more questions:

What’s a difference between “Additional Non-Asset Directories to Package” and “Additional Non-Asset Directories to Copy” ?

FPaths::GameContentDir() returns …/…/…/MyProject/Content/ (the Windows path) and the file is in /storage/emulated/0/MyProject/MyProject/Content/ (I build in Development Configuration). Is there a method to get a correct path? When the game will be built to the apk… will be there even a possibility to pass a file path?

The difference is there when you use PAK file. In that case To Package means to add folder to PAK file and To Copy means just to copy it to cooked Contents directory.

Do you check FPaths::GameContentDir() on your device or in editor?

I checked it on device.

Well, it’s quite complicated, but for now to get proper absolute path to the content file I’m using such code:

FString AbsoluteContentPath = GFilePathBase + TEXT("/") + GGameName + TEXT("/") + FString::Printf(TEXT("%s/Content/"), FApp::GetGameName());

For development mode works well.

Hi, I have a same problem on ios. Have you found a correct path to find the custom files on ios?

On UE 4.7.3 I found a better solution.

On Android I’m using a PathToAndroidPaths function from Engine\Source\Runtime\Core\Private\Android\AndroidFile.cpp

On IOS I’m using a ConvertToIOSPath function from Engine\Source\Runtime\Core\Private\IOS\IOSPlatformFile.h

On PC I’m using a FPaths::ConvertRelativePathToFull function from Engine\Source\Runtime\Core\Public\Misc\Paths.h

Most of those function are private, so I made a new, public function that use them for converting relative path to the absolute one.

The ConvertRelativePathToFull from FPaths works correctly only for PC, it doesn’t return correct absolute paths for mobile devices.


I almost forgot about this question.

I’ve solved the problem in the meantime, I’ve posted the solution in the answer.

It works with Launch, but when packaging APK, files don’t appear in that folder.

Actually my version:

GFilePathBase + FString("/UE4Game/") + FApp::GetGameName() + TEXT("/") + FApp::GetGameName() + FString("/Content");

Hi, I am facing the same problem right now. My content seems to not get packaged. Instead all of them are stored in the obb file (my guess). May I ask how you go around it?

I think this is a desirable situation that the content goes to OBB file. If You want to have something in APK the best option is tu put them to the YourGame/Build/Android/assets directory. But even then they won’t be accessible by UnrealEngine easily. I wrote a function that copies files from assets to external storage. I relied on this solution:

There is also somethin like put obb into apk option, but never tried it :confused:

When I go back to work on Monday I’ll try to dig around my old code, because this is quite twisted problem and put the official solution with paths :wink:

Thanks for replying! I will look into that.

I am relatively new to Android development so I am a bit confused about how Android system works, especially with Unreal. From my understanding, Unreal packages a project with an apk file (not sure whats inside) and an obb file(Content folder of the project). After it is installed, the obb file is located at external storage while the apk is broke down into base.apk and serveral so file in data/data/app. Is my understanding correct?

Also I heard some rumors about app not allowed to access certain areas of the android system. Like The Storage Situation: Removable Storage

Sorry for the amount of questions :confused:

Well, Android always confuses me more than iOS. I hope someone else will tell if we are correct, but anyway, this is how it works (I think) :wink:

First of all - all content goes to OBB. You can decide which one goes to a PAK file and which one are outside of it, but the main design of Android is that content goes to the OBB.

If You really want to have files inside the APK, then the assets or raw directory is a good place (I recommend the assets directory, the raw directory had some issues with ant build scripts).

Where the files are… it depends how you deploy to the Android.
If you run it via Unreal Frontend then all files are places in the /sdcard/UE4Game/YourApp/
If you install it from APK+OBB then the files are located in the /sdcard/Android/data/com.YourCompany.YourApp
The APK data are stored in /data/data/YourApp

Unfortunately, the APK and OBB files are hidden because of the security reasons and, without rooting it, it is not possible to check them. This is why when You deploy using Unreal Frontend files are put into the public place so You can check what is going on.

And this is the major issue - if you need other application or library to have a direct access to the file that is inside the APK you need to move this file somewhere else, where it is public.

But hey… UnrealEngine uses content from OBB so it can be read! They are probably read by methods from AndroidFile.cpp but using it is kinda painful…

At this point it depends on what You are trying to do. With this information we might find a solution :wink: