Skip to content

Need fix for Android builds #14

@mjolner36

Description

@mjolner36

2025.09.26 11:28:19.772 8257 8411 Info SwappyDisplayManager Terminating looper thread
2025.09.26 11:28:19.780 8257 8306 Error SwappyDisplayManager dalvik.system.InMemoryDexClassLoader[DexPathList[[dex file "InMemoryDexFile[cookie=[-5476376606068064000, -5476376606068851328]]"],nativeLibraryDirectories=[/system/lib64, /system_ext/lib64]]] couldn't find "libgame.so"
2025.09.26 11:28:19.927 8257 8477 Error Unity Failed to load gameplay tags from StreamingAssets: Could not find a part of the path "/jar:file:/data/app/~~VfVdO7Zr6pjQxZNcT6Gk9g==/com.UnityTechnologies.UniversalMobile3DTemplate-CAMgyFsbqThb3aR-WQhY1g==/base.apk!/assets/GameplayTags".
2025.09.26 11:28:19.927 8257 8477 Error Unity UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
2025.09.26 11:28:19.927 8257 8477 Error Unity BandoWare.GameplayTags.BuildGameplayTagSource:RegisterTags(GameplayTagRegistrationContext)
2025.09.26 11:28:19.927 8257 8477 Error Unity BandoWare.GameplayTags.GameplayTagManager:InitializeIfNeeded()
2025.09.26 11:28:19.927 8257 8477 Error Unity BandoWare.GameplayTags.GameplayTagManager:TryGetDefinition(String, GameplayTagDefinition&)
2025.09.26 11:28:19.927 8257 8477 Error Unity BandoWare.GameplayTags.GameplayTagManager:RequestTag(String, Boolean)
2025.09.26 11:28:19.927 8257 8477 Error Unity BandoWare.GameplayTags.GameplayTagContainer:UnityEngine.ISerializationCallbackReceiver.OnAfterDeserialize()

My solution

using System;
using System.IO;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;

namespace BandoWare.GameplayTags
{
    internal class BuildGameplayTagSource : IGameplayTagSource
    {
        public string Name => "Build";

        public void RegisterTags(GameplayTagRegistrationContext context)
        {
            try
            {
                string src = Path.Combine(Application.streamingAssetsPath, "GameplayTags");

                byte[] data = LoadStreamingAssetBytes(src);

                MemoryStream ms = new MemoryStream(data);
                BinaryReader reader = new BinaryReader(ms, Encoding.UTF8, false);

                while (ms.Position < ms.Length)
                {
                    string tagName = reader.ReadString();
                    context.RegisterTag(tagName, string.Empty, GameplayTagFlags.None, this);
                }

                reader.Dispose();
                ms.Dispose();
            }
            catch (Exception e)
            {
                Debug.LogError($"Failed to load gameplay tags from StreamingAssets: {e.Message}");
            }
        }

        private static byte[] LoadStreamingAssetBytes(string absolutePath)
        {
            if (absolutePath.Contains("://") || absolutePath.StartsWith("jar:", StringComparison.OrdinalIgnoreCase))
            {
                UnityWebRequest req = UnityWebRequest.Get(absolutePath);
                UnityWebRequestAsyncOperation op = req.SendWebRequest();
                while (!op.isDone) { }

#if UNITY_2020_2_OR_NEWER
                if (req.result != UnityWebRequest.Result.Success)
#else
                if (req.isNetworkError || req.isHttpError)
#endif
                {
                    string err = req.error;
                    req.Dispose();
                    throw new IOException($"StreamingAssets load failed: {err} | {absolutePath}");
                }

                byte[] bytes = req.downloadHandler.data;
                req.Dispose();

                if (bytes == null || bytes.Length == 0)
                    throw new IOException($"Empty data from StreamingAssets: {absolutePath}");

                return bytes;
            }
            else
            {
                if (!File.Exists(absolutePath))
                    throw new FileNotFoundException($"File not found in StreamingAssets: {absolutePath}");
                return File.ReadAllBytes(absolutePath);
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions