Troubleshooting Godot Script: Android vs. Windows

Godot Version

v4.2.3.rc.custom_build

Question

Hey everyone, I’m encountering an issue with a Godot script that behaves differently on Android compared to
Windows. Here’s the script in question:

var file = FileAccess.open("res://icon.png", FileAccess.READ)
var path = file.get_path_absolute()
print(path)

The script is intended to open a file (“icon.png”) and print its absolute path. Surprisingly, it works as expected on Windows but fails on Android. I’m puzzled by this discrepancy and would appreciate any insights or potential solutions to make it work consistently across both platforms.

I want this because I need to pass the absolute path to my Custom Modules in C++.

Thank you in advance for your help!

Some people have said you need to include resources in your export.

Just be aware that android apps typically don’t have permissions by default, and there are restrictions for what files paths can be accessed.

If i remember well, you can’t access android exported files like that because in the exported version the file used is in an especific format that Godot uses.

From the FileAccess documentation:

bool file_exists ( String path ) static

Returns true if the file exists in the given path.

Note: Many resources types are imported (e.g. textures or sound files), and their source asset will not be included in the exported game, as only the imported version is used. See ResourceLoader.exists for an alternative approach that takes resource remapping into account.

For a non-static, relative equivalent, use DirAccess.file_exists.