-
Notifications
You must be signed in to change notification settings - Fork 509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android: bundle resources in sokol-samples build script #357
Comments
Just linking some related tickets and PRs, I need to do another round of Android fixes eventually. I'm currently not sure if file loading ever worked on Android, the required assets might not be copied onto the device (in "fips run"), or sokol_fetch.h might attempt to load them from the wrong location. |
Ok, I just checked, and the loadpng-sapp sample indeed doesn't work (or any of the other samples loading files), this is because there's no mechanism in place yet to package the resource files into the APK. |
@floooh Thank you so much for looking into it! What's the rough timeline for adding this mechanism? |
I don't know. I don't commit to timelines for my hobby stuff ;) This isn't a sokol issue though but a toolchain / build-system issue, so a fix would need to go into fips (and people using other build systems would need to come up with their own solution). |
@floooh Thank you for the quick reply! Is there a way to get assets into the APK "manually" so sokol_fetch.h finds them? |
I think this requires two things:
This assumes that Android maps the APK content into the filesystem, which I'm not sure of. It's been a long time since I looked at this. |
In case this is useful, I solved this by modifying your android packaging script. Then I add them to the unaligned To access the files later from a #include <android/native_activity.h>
// returns a heap allocated binary data buffer, null terminated when reading as a string (read_str == true)
unsigned char* android_fileRead(ANativeActivity* nativeActivity, const char* file_name, int* out_buffer_size, bool read_str) {
AAssetManager* asset_manager = nativeActivity->assetManager;
AAsset* asset = AAssetManager_open(asset_manager, file_name, AASSET_MODE_UNKNOWN);
int size = AAsset_getLength(asset);
// if reading as a string, then add 1 extra byte for the null char
unsigned char* data_buffer = ce_calloc(1, sizeof unsigned char * (size + (read_str ? 1 : 0)));
*out_buffer_size = AAsset_read(asset, data_buffer, size);
AAsset_close(asset);
if (read_str) {
data_buffer[size] = '\0';
*out_buffer_size = *out_buffer_size + 1;
}
return data_buffer;
} |
After starting the sample "loadpng-sapp" on Android 9 I just see a solid red screen. Other samples seem to work fine.
I built the sample on Windows 10 using these commands:
The text was updated successfully, but these errors were encountered: