How to get a working Android Savegame [Tutorial]

Hello,

I have seen many people writing that their savegame works on their computer but not on their Android device. This is because Google has introduced scoped storage with Android 10.
https://developer.android.com/about/versions/11/privacy/storage

I have found a solution that is not quite perfect because it only works in Shipping Mode if you only want to test your game you should set the Target SDK to 28 (Android 9).

The steps you need to do to get your savegame working on your Android devices are:
ă…¤
ă…¤
Step 1.

Set the build configuration to Shipping and check “Full Rebuild” and “For Distribution”.


ă…¤
ă…¤
ă…¤
Step 2.

Set the Target SDK to 31 and check “Use ExtenalFilesDir for UE4Game files?”


ă…¤
ă…¤

Step 3.

Open the windows prompt and go to the Java/jre/bin folder with the command “cd C:\Program Files\Java\jre1.8.0_291\bin” (If you installed it somewhere else, enter your own installation directory).

Step 4.

Enter this command to generate the Keystore.

keytool -genkey -v -keystore ExampleKey.keystore -alias MyKey -keyalg RSA -keysize 2048 -validity 10000


ă…¤
ă…¤
Step 5.

Create a password for your Key Store and answer all the questions that are asked.
If it says [Storing ExampleKey.keystore], everything worked.


ă…¤
ă…¤
Step 6.

Copy the ExampleKey.keystore file from the Java/jre/bin folder into the Build/Android folder.

ă…¤
ă…¤
Step 7.

Go to the Android Project Settings in the Unrel Engine and scroll down to “Distribution Signing”.
Enter the full filename, Alias and password of your Key Store.

ă…¤
ă…¤
Step 8.

Package your game and your savegame should work.
ă…¤
ă…¤
ă…¤
Extra information:

I have often read that people think that the savegame is deleted after an update but that is not the case at least if you update with the apk. I don’t know how it is via the playstore.

I hope this tutorial can help you if I have made any mistakes let me know
ㅤㅤ
ă…¤
ă…¤
I have also made a youtube video that shows all the steps of this tutorial.

1 Like


that’s how i fixed it … and updating from play store my game on android 11 doesn’t remove my save

1 Like

Thanks for the tutorial, however I’ve followed all these steps exactly on Unreal 5.0.3 with android 11 (galaxy s22) and this still does not work. Save games work fine on the PC, but just refuse to work on android.

I should note that after applying your changes, when I uninstalled and installed (to make sure it was fresh) it was not asking me for file permission this time when it had been asking every time previous.

I went to the app and manually gave it file permission, but it still didn’t work.

I decided to download source and make a source build. I did that and made your change as you indicated here. This made no difference. I also tried another change someone else has suggested:

This needs to be added to the libraries on top of the class.
#include "Misc/App.h"

And this is how I solved the SaveGame implementation.

virtual FString GetSaveGamePath(const TCHAR* Name)
    {
#if PLATFORM_ANDROID 
        // ProjectSettings->Platforms->Android->APKPackaging->AndroidPackageName()
        FString BundleID = FString(FPlatformProcess::GetGameBundleId()); 

        // ProjectSettings->Description->ProjectName()
        FString AppName = FString(FApp::GetProjectName());  
             
        return FString::Printf(TEXT("/storage/emulated/0/Android/data/%s/files/UE4Game/%s/%s/Saved/SaveGames/%s.sav"), *BundleID, *AppName, *AppName, Name);    
#else
        return FString::Printf(TEXT("%sSaveGames/%s.sav"), *FPaths::ProjectSavedDir(), Name);
#endif
    }

This has also resulted in it not working. Can you think of anything else that would prevetn the game from saving properly? I’ve verified the app has permission and it is properly asking for permission

Hello crossmr

I have tried it with the test app shown in the tutorial with the unreal engine 5.0.3 on several devices and the savegame works on all of them.
(I tested it on a Oneplus 8T, Redmi Note 9 Pro and Samsung Galaxy A31).

I have uploaded the Project files and APKs that were made with UE 4.26 and 5.0.3 so you can check if it works for you.

https://drive.google.com/drive/folders/1LmYkJDdi2j_Wm4B0CrPfOAsZOvwv6Q84?usp=sharing

Thank you, I’ll give that a shot and see if those work for me.