I would like to bundle generic files into my android apk and have them appear in applicationStorageDirectory/files/.
First I thought that this is done through the assets tag in the project file, but that does not seem to work like that.
Is there a way to just include a given file so that it exists as a file in an android target?
<template path="androidFiles/MyFile.bin" rename="applicationStorageDirectory/files/MyFile.bin" if="android" />
That does not seem to work - I cannot find the file on my android device at all when I use the template tag?
I thought that the template tag just copied stuff into your project dir before compiling… Did I misunderstand something here?
It does. I assumed you were just trying to place it in an unusual folder within the APK. But now that I think about it, my suggestion wouldn’t even have worked for that.
If you’re trying to place a file on the device, you’ll need to go through a few steps.
- Copy it into the APK.
- Install the APK on the device.
- Copy the file from the APK to the device.
The easiest way to do this is probably using OpenFL’s assets system. Step 1:
<assets path="androidFiles/MyFile.bin" rename="binary/MyFile.bin" type="binary" if="android" />
var myFile:ByteArray = Assets.getBytes("binary/MyFile.bin");
var output:FileOutput = File.write(
output.writeBytes(myFile, 0, myFile.length);
Yes, the asset way would work but perhaps be a bit of a waste of memory since the file would be duplicated as a resource forever.
It doesn’t look like there’s an alternative, sorry.
I see - you’re right! Thanks for answering!