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.
- Create the file (if not available) before accessing it.
- 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.");
}
}
}
Whenever I tap on
Build & Runin unity. SimpleBuildbutton is working fine.I encounter this error
Package version not foundThis is because,
MeticaEditorUtilities.csdoes not create any file ifsdkInfo.jsonis not available inside streaming assets.We have two solutions here.
Here is the actual method
Here is the fix (I applied the second solution)