Bundling files into android apk

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.

  1. Copy it into the APK.
  2. Install the APK on the device.
  3. 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" />

Step 3:

var myFile:ByteArray = Assets.getBytes("binary/MyFile.bin");
var output:FileOutput = File.write(
    + "/files/MyFile.bin");
output.writeBytes(myFile, 0, myFile.length);

(Not tested.)

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!