X Tutup
Skip to content

Android: App using Gradle Build crashes when saving files with FILE_DIALOG_MODE_OPEN_DIR #117111

@OverloadedOrama

Description

@OverloadedOrama

Tested versions

  • Reproducible in Godot 4.6.1

System information

Godot v4.6.1.stable - Android 13 (SDK 33 build V14.0.2.0.TKIEUSF) - Single-window, 1 monitor - OpenGL ES 3 (Compatibility) - Adreno (TM) 642 - (8 threads)

Issue description

When trying to save a file from an exported Android project using Gradle Build and using the FileDialog's Open Folder file mode (FILE_DIALOG_MODE_OPEN_DIR), the app immediately crashes. This error appears twice in Godot's Debugger panel:

E 0:00:06:184   control.gd:22 @ _on_file_dialog_dir_selected(): File must be opened before use.
  <C++ Error>   Condition "!is_open()" is true. Returning: false
  <C++ Source>  platform/android/file_access_filesystem_jandroid.cpp:242 @ store_buffer()
  <Stack Trace> control.gd:22 @ _on_file_dialog_dir_selected()

If the exported project is not using Gradle build, the crash does not occur and the file gets saved normally.

Steps to reproduce

  • Create an empty project with a Button and a FileDialog. The FileDialog must be a native dialog and its file mode set to Open Folder, and Access mode set to File System.
  • Attach a script to the root node and paste the following code (and connect the appropriate signals):
extends Control

const ICON := preload("res://icon.svg")

@onready var file_dialog: FileDialog = $FileDialog


func _on_save_image_button_pressed() -> void:
	file_dialog.popup_file_dialog()


func _on_file_dialog_dir_selected(dir: String) -> void:
	var file_path := dir
	if OS.get_name() == "Android":
		file_path += "#" + "icon.png"
	else:
		file_path = file_path.path_join("icon.png")
	ICON.get_image().save_png(file_path)
  • Go to Project > Export, add an Android preset and enable "Use Gradle Build". Then, go to Project > Install Android Build Template
  • Run the project in your Android device (I did it from my PC using Remote Deploy, while my phone was connected to my PC via USB)
  • Attempt to save the file. The app should crash.

Minimal reproduction project (MRP)

android-saf-save-image.zip

Metadata

Metadata

Type

No type

Projects

Status

Very Bad

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions

    X Tutup