Android permission and file access issue

Hello there,

I am struggling with an issue related to the access permission for the Android build, and read and write files on Android platform.
This issue is strange, and the issue happened when I changed the Project Settings/Packaging/Project “Build Configuration” from Development to Shipping and clicked “For Distribution” to true. After applying the changes, the build is having issues with “actual” access to the file on Android devices. What I mean by “actual” is the app has the AndroidManifest set with the read and write permission, I edit the ProjectSettings/Platforms/Android and set “Extra Permissions” with “android.permission.WRITE_EXTERNAL_STORAGE” and “android.permission.READ_EXTERNAL_STORAGE”, also when the first time opens the app, the app asks for permission to access the file. To confirm the app has access permission to the file I have used the debug code to show if the app has the proper permission to access the file,

bool bHasReadPermission = UAndroidPermissionFunctionLibrary::CheckPermission("android.permission.READ_EXTERNAL_STORAGE");
UE_LOG(LogTemp, Display, TEXT("Has Read Permission: %s"), bHasReadPermission ? TEXT("True") : TEXT("False"));

LogPlayLevel: UAT: 09-22 22:54:20.728 12324 12934 D UE      : [2024.09.23-02.54.20:728][  0]LogAndroidPermission: UAndroidPermissionFunctionLibrary::CheckPermission android.permission.READ_EXTERNAL_STORAGE (Android)
LogPlayLevel: UAT: 09-22 22:54:20.729 12324 12934 D UE      : [2024.09.23-02.54.20:729][  0]LogTemp: Display: Has Read Permission: True

which is true for read permission. For why is the app is asking for access to the file on Android, because the app need to create .json file to save and read the in-app progress data, also I wish to allow the app able to download APK and install APK without using the Google service. The STRANGE things happened, I used code to check if the access file existed,

FString FilePath = TEXT("/storage/emulated/0/Download/appdata.json");
FString JsonContent;
    // Check if the file exists and load it
    if (FPlatformFileManager::Get().GetPlatformFile().FileExists(*FilePath))
    {
        if (FFileHelper::LoadFileToString(JsonContent, *FilePath))
        {
            UE_LOG(LogTemp, Log, TEXT("File loaded successfully: %s"), *FilePath);
        }
        else
        {
            UE_LOG(LogTemp, Error, TEXT("Failed to load file: %s"), *FilePath);
        }
    }
    else
    {
        UE_LOG(LogTemp, Error, TEXT("File does not exist: %s"), *FilePath);
    }

the app is throwing an error message that failed to load the file.

LogPlayLevel: Error: UAT: 09-22 22:54:20.735 12324 12934 D UE      : [2024.09.23-02.54.20:735][  0]LogTemp: Error: Failed to load file: /storage/emulated/0/Download/appdata.json

Long story short, the app has assigned permission to read and write files, the app can read and write files. But when reading and writing files the app throws an error message.

The issue happened when I switched the build from development to distribution. To resolve the issue usually just reverse what I am doing and change the build type back to development. But in this case is not working. Looks like is not way back.

To prove the development to distribution step caused the issue, I used a new project and did the testing, in the development build the app is fine with access to the file, but in the distribution build, the build cannot read the same file. In the testing project, I resolved this issue by simply reversing my process and changing back to the development build, and the file permission issue is gone.

I also tried many other ways to resolve this issue. I have reversed all my changes on GitHub and back to last week’s version then started to rebuild the app. Which does not help with the issue. I also tried to download the repository from GitHub and started from fresh. Which is also not working. And make other project settings and plugin changes to see if those are causing the issues. Unfortunately, none of those works.

If anyone has solutions or suggestions for the issues, I would be glad to hear from you.

I am using Unreal Engine 5.3.2, and Minimum SDK Version 29, Target SDK Version 30.

Copy here. UE 5.3 in development
Trying to access text file in Android with 3 different plugins and now trying with custom code with always same behavior: crash when trying to read the file.
image
image

No luck until now, looking for a solution