Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | e8johan |
I’m making a spelling game, and the words to be spelled are encoded as the filenames of the image resources of the game. This works fine on desktop, however, once deploying to Android, it fails miserably.
The code in question is:
var _words : Array = Array()
func _init() -> void:
var dir = Directory.new()
if dir.open("res://assets/images/words") == OK:
dir.list_dir_begin()
var filename = dir.get_next()
while (filename != ""):
if filename.ends_with(".png"):
_words.append(filename.left(filename.length()-4))
filename = dir.get_next()
The issue is that the _words array is empty on the Android device. I’ve tried adding the resources using the Project → Export → Android → Resources → Filters to export non-resource files, where I set the filter to *.png. I’ve also tried adding a Node that refers to all the images by including them as sprites. As neither of these tricks work, I’ve come to the conclusion that the dir() function in combination with res:// paths does not work on Android. Is that by design, or should I report a bug?
Are you sure that you did write the directory path correctly? Especially in terms of uppercase/lowercase characters? Remember that Android (just like i.e. linux) is case sensitive in path and file names (extensions as well).
If you develop on Windows then you wouldn’t notice it as Windows isn’t case sensitive on file names.
I would start opening just res:// and listing the contents to output (and check the output either with adb logcat or inside the godot IDE.
wombatstampede | 2020-01-26 13:39
It works on Linux (debian), so I think the case sensitivity should be ok. I’ll add some output and see what goes on on the phone compared to desktop.
e8johan | 2020-01-26 19:54
You need to have permisson check in export project settings when exporting for android under export settings
Okan Ozdemir | 2020-03-29 11:23