Use a base path of "./" on Android
This allows filesystem operations to use internal storage and the asset system by default.
diff --git a/include/SDL3/SDL_filesystem.h b/include/SDL3/SDL_filesystem.h
index dd9430a..df043a0 100644
--- a/include/SDL3/SDL_filesystem.h
+++ b/include/SDL3/SDL_filesystem.h
@@ -77,6 +77,8 @@
* - `parent`: the containing directory of the bundle. For example:
* `/Applications/SDLApp/`
*
+ * **Android Specific Functionality**: This function returns "./", which allows filesystem operations to use internal storage and the asset system.
+ *
* **Nintendo 3DS Specific Functionality**: This function returns "romfs"
* directory of the application as it is uncommon to store resources outside
* the executable. As such it is not a writable directory.
diff --git a/src/filesystem/android/SDL_sysfilesystem.c b/src/filesystem/android/SDL_sysfilesystem.c
index bb42409..69577fb 100644
--- a/src/filesystem/android/SDL_sysfilesystem.c
+++ b/src/filesystem/android/SDL_sysfilesystem.c
@@ -31,9 +31,7 @@
char *SDL_SYS_GetBasePath(void)
{
- // The current working directory is / on Android
- SDL_Unsupported();
- return NULL;
+ return SDL_strdup("./");
}
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
diff --git a/src/storage/generic/SDL_genericstorage.c b/src/storage/generic/SDL_genericstorage.c
index 8ba4231..8d2180d 100644
--- a/src/storage/generic/SDL_genericstorage.c
+++ b/src/storage/generic/SDL_genericstorage.c
@@ -263,12 +263,7 @@
}
} else {
const char *base = SDL_GetBasePath();
- // On Android, SDL_GetBasePath() can be NULL: use empty base.
-#ifdef SDL_PLATFORM_ANDROID
- basepath = base ? SDL_strdup(base) : SDL_strdup("");
-#else
basepath = base ? SDL_strdup(base) : NULL;
-#endif
}
if (basepath != NULL) {
@@ -343,8 +338,13 @@
SDL_Storage *result;
char *basepath = NULL;
char *prepend = NULL;
- bool is_absolute = false;
+#ifdef SDL_PLATFORM_ANDROID
+ // Use a base path of "." so the filesystem operations fall back to internal storage and the asset system
+ if (!path || !*path) {
+ path = "./";
+ }
+#else
if (!path || !*path) {
#ifdef SDL_PLATFORM_WINDOWS
path = "C:/";
@@ -353,6 +353,7 @@
#endif
}
+ bool is_absolute = false;
#ifdef SDL_PLATFORM_WINDOWS
const char ch = (char) SDL_toupper(path[0]);
is_absolute = (ch == '/') || // some sort of absolute Unix-style path.
@@ -367,6 +368,7 @@
return NULL;
}
}
+#endif // SDL_PLATFORM_ANDROID
const size_t len = SDL_strlen(path);
const char *appended_separator = "";