Hello,
At a certain point, early in the game start, I copy baked-in template sqlite files to a place where the game can access later on, and edit these data as the player progresses in the game. That works beautifully, for all platforms I am currently supporting, which for now is Android, iOS and desktop (I have tested on Mac only so far)(the game is in an early development stage). Well, the code that copies over from the content folder to the “documents” folder is different for each platform, as it seems to be platform specific.
Now, when I package the app for distribution however (I’m doing this regularly even in early development stage so that product and designer can check), these template database files do not get copied over to the app’s folder! That is for Android only, and shipping builds. All other conditions work as expected.
This is the code that I am using (the Android part only):
static constexpr TCHAR DatabaseDirectory[] = TEXT("Data");
static constexpr TCHAR DatabaseExtension[] = TEXT(".db");
...
#elif PLATFORM_ANDROID
extern FString GInternalFilePath;
FString DatabaseFileManager::DatabaseFilePath(FString DatabaseName)
{
FString FileName = DatabaseName.Append(DatabaseExtension);
IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
FString DestinationDatabasePath = GInternalFilePath / FileName;
if (!PlatformFile.FileExists(*DestinationDatabasePath))
{
FString OriginDatabasePath = FPaths::ProjectContentDir() / DatabaseDirectory / FileName;
//check(PlatformFile.CopyFile(*DestinationDatabasePath, *OriginDatabasePath));
if (!PlatformFile.CopyFile(*DestinationDatabasePath, *OriginDatabasePath))
{
UE_LOG(LogTemp, Error, TEXT("Copying database was NOT successful"));
checkNoEntry();
};
}
return DestinationDatabasePath;
}
#else
...
What I’ve done:
- I added my Data folder under the Content folder
- I marked my Data folder as a non-asset folder to be packaged, under the Packaging project settings
Tests I’ve run so far:
- After apk and obb files generated, I extracted the contents out of the obb files, and extracted the generated pak file with the UnrealPak tool, and the Data folder is present, just as expected; both development and shipping builds;
- After installing the app on a Samsung J4 Core device:
- Development build, the above code is executed, and the template files are copied over to the path
/data/data/my.package.name/files
. The app behaves seamlessly as expected. Thus, theUE_LOG
doesn’t print any error. - Shipping build, I checked the same path, and my files are not present. The app behaves accordingly, i.e. not showing the data that is in the template database files. I don’t know how to check
UE_LOG
errors on a shipping build, if it is withadb logcat
then nothing is printed there either. But the fact is the files are not there.
- Development build, the above code is executed, and the template files are copied over to the path
Originally I was using GExternalFilePath
, with the very same results. But since I discovered the Internal path, I preferred this approach because the template files are tiny, and I don’t have the risk of the user refusing the external storage permission.
I am two days on it, have researched all through the forums and all the the internet could offer, and I have no extra light. Any help, that could point to a brighter direction is much much appreciated.