4.10 Android package custom files along

I have implemented a third party library which reads in calls python function from c++. The problem I have is I cannot package the python files along with the game. I tried the “non-asset content to copy” and it did not work. Seems like all I had is a huge obb file instead of the seperate file. I can’t even find the content folder on my Android. Is there anyway of doing it?

Thanks in adavance

Hi FrankKappaPride,

You can place your files in a directory in the project’s Content directory and add it to the “non-asset content to copy” package settings. The files will be in the OBB so you will need to use the UE filesystem to read them. If your third party library only does native file reads without a way to override the source, you will need to copy the files on startup to the GExternalFilePath (you can check if one of the file already exists to skip copying them again).

I gave an example in this forum post:

Hi Chris
Thanks for the reply!
My python library requires the file to be loss file in the directory so reading as FString would not help much. Can you explore a bit more on the GExternalFilePath you mentioned?
Also I have another question. When I package the game I can see the obb file with all the content inside. But when I choose the package with apk only, not only the obb file is gone, I can’t find the content folder either. Do you have any idea where the content will be after installation?

Also, do you know how I can access the GExternalFilePath or the private function PathToAndroidPaths function from Engine\Source\Runtime\Core\Private\Android\AndroidFile.cpp

Hi FrankKappaPride,

The OBB is embedded in the APK in the assets directory as “main.obb.png”.

just use extern FString GExternalFilePath and protect any code using it with #if PLATFORM_ANDROID / #endif.

Something like this should copy all the files in the provided directory (assuming it was in Contents) to GExternalFilePath:

void CopyAllAssetsToExternal(FString inDirectory)
	// only do this on Android
	extern FString GExternalFilePath;
	FString DirectoryPath = FPaths::GameContentDir() / inDirectory;
	IFileManager* FileManager = &IFileManager::Get();

	// iterate over all the files in provided directory
	TArray<FString> directoriesToIgnoreAndNotRecurse;
	FLocalTimestampDirectoryVisitor Visitor(FPlatformFileManager::Get().GetPlatformFile(), directoriesToIgnoreAndNotRecurse, directoriesToIgnoreAndNotRecurse, false);
	FileManager->IterateDirectory(*DirectoryPath, Visitor);

	for (TMap<FString, FDateTime>::TIterator TimestampIt(Visitor.FileTimes); TimestampIt; ++TimestampIt)
		// read the file contents and write it if successful to external path
		TArray<uint8> MemFile;
		const FString SourceFilename = TimestampIt.Key();
		if (FFileHelper::LoadFileToArray(MemFile, *SourceFilename, 0))
			FString DestFilename = GExternalFilePath / FPaths::GetCleanFilename(*SourceFilename);
			FFileHelper::SaveArrayToFile(MemFile, *DestFilename);

Then you can give the filename to your third-party library prefixed with GExternalFilePath.

Thank you very much Chris! This is excat what I am looking for.
Do you know if there is anyway of keeping the folder after copying?
Also just to make sure, files copied like this will still have the same characters? Because I did a textfile to test and the copied one seems to be different judging by vim.

The files in GExternalFilePath persist, but are removed if you uninstall the app. If you do “adb install -r my.apk” instead of doing the uninstall the batch files does, I believe your files should still be there. You can check with FPaths::FileExists() on one of the files to skip doing the whole directory.