Not embedded resources on android


#1

Hi!

First of all, this is my setup to get the heaps-android project if someone is interested:

  • heaps 1.6.1 (haxelib)
  • hlsdl 1.9.0 (haxelib)
  • Haxe 4.0.0-rc.2
  • Hashlink 1.10
    • Clone the heaps-android-app branch of the project above and update HL dependency to the latest
    • Update the CMakeLists.txt file to add hashlink/include/minimp3 in the target_include_directories of fmt.hdll
  • CMake 3.6 (from android SDK manager)
  • NDK 17.2 (from android SDK manager)
  • Tested in android studio 3.2.1 and 3.5.1

Well, it’s awesome to get heaps on android! But I only could get the resources using initEmbed. And here comes the question:

How or where can I put the .pak file in the android project to get the resources from Heaps?

thanks in advance


#2

I am going to try this soon but the .pak file should be in the res/ assets directory of the Android Studio library which maybe you know. So when it’s finally compiled into the app.apk, it’s contained.

The question is, how can we get that resource that is serialized in Android back into the Heaps runtime, this I don’t know because I don’t yet have enough lab time.

Will write a doc when I get it running.


#3

Hi!

Thanks for the response! I think I tried the assets directory but couldn’t get the pak file back to read.

As the project was growing, the resources took more and more space and I finally saw that I should use an expansion pack for my app. So that was the way to go:

  • Rename the res.pak with the android expansion pack convention
  • Get the OBB file path from C. Add glue code in sys_android.c. There is no need to add that function to the android activity, since it is directly called from C to the android Context.
  • Get that path from haxe with something like this
@:hlNative("std", "sys_special")
    static function sys_special( key : hl.Bytes ) : Null<hl.Bytes> { return null; }
    static public function get(key:Key) {
        try {
            var sd = sys_special(key.toUtf8());
            return (sd == null)
                    ? key
                    : String.fromUTF8(sd);
        } catch(e:Dynamic) {
            return Std.string(e);
        }
    }

    //
    var obbDir = Syspecial.get('android_obb_storage_path');
    var pakName = obbDir + '/main.1.my.pack.app.obb';
    var pak = new hxd.fmt.pak.FileSystem();
    pak.loadPak(pakName);
    hxd.Res.loader = new hxd.res.Loader(pak);

  • I think I fixed some naming in the android-studio project: the activity package/name and some other little fixes I found along the way.

I didn’t came back to write about it because I thought there was no interest in this. But here is my experience if it can be helpfull.

I would love to read the documentation you create!