Skip to content

Issue - Build & Run fails with "Package version not found" error #81

Description

@ahmadrazagd

Whenever I tap on Build & Run in unity. Simple Build button is working fine.
I encounter this error Package version not found

This is because, MeticaEditorUtilities.cs does not create any file if sdkInfo.json is not available inside streaming assets.

We have two solutions here.

  1. Create the file (if not available) before accessing it.
  2. Skip file checking using if statement

Here is the actual method

internal static void WriteJsonSdkInfo()
{
    string sdkInfoFolder = SdkInfo.SdkInfoFolder;

    if (!Directory.Exists(sdkInfoFolder))
    {
        Directory.CreateDirectory(sdkInfoFolder);
        AssetDatabase.Refresh();
    }

    string filePath = Path.Combine(sdkInfoFolder, "sdkInfo.json");

    string packageVersion = GetPackageVersion("com.metica.unity");
    if (packageVersion != null)
    {
        string jsonData = $"{{\"Version\": \"{packageVersion}\"}}";  // Ensure version is quoted for valid JSON
        File.WriteAllText(filePath, jsonData);
        AssetDatabase.Refresh();
    }
    else
    {
        Debug.LogError("Package version not found.");
    }
}

Here is the fix (I applied the second solution)

internal static void WriteJsonSdkInfo()
{
    string sdkInfoFolder = SdkInfo.SdkInfoFolder;

    if (!Directory.Exists(sdkInfoFolder))
    {
        Directory.CreateDirectory(sdkInfoFolder);
        AssetDatabase.Refresh();
    }

    string filePath = Path.Combine(sdkInfoFolder, "sdkInfo.json");

    if (File.Exists(filePath))
    {
        string packageVersion = GetPackageVersion("com.metica.unity");
        if (packageVersion != null)
        {
            string jsonData =
                $"{{\"Version\": \"{packageVersion}\"}}"; // Ensure version is quoted for valid JSON
            File.WriteAllText(filePath, jsonData);
            AssetDatabase.Refresh();
        }
        else
        {
            Debug.LogError("Package version not found.");
        }
    }
}

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