I am trying to figure out a bug that is happening only on my iOS device (iPhone4) and I am having a problem figuring out why my Post-Export methods are failing.
My full cloud build log fails with no additional info:
ERROR: postExportMethod ‘PostExport.PostExportMethod’ failed, aborting.
I don’t have my OSX machine right now so I am trying to build a development build to show debug logs and crash reports on the screen of my game.
To enable crash reports, the documentation shows that I need to change a value in a file Classes/CrashReporter.h created as a result of building iOS project before building in xcode.
I find that I can do that in cloud build by entering the name of the static method in my project that will do the file processing stuff in Post export phase (after Unity editor build and before importing to xcode) https://build-beta.cloud.unity3d.com/support/guides/advancedfeatures/
I have entered the name of the method in Post-Export Method Name box in my project’s advanced options.
So I wrote the method like this.
It changes the value correctly on my computer, when I call it providing the right path to the build folder.
But it does not work on cloud build. Can anybody explain what am I doing wrong.
using System;
using System.IO;
public class PostExport
{
public static void PostExportMethod(string ExportPath)
{
try
{
var filePath = Path.Combine(ExportPath, @"Classes\CrashReporter.h");
if (File.Exists(filePath))
{
var lines = File.ReadAllLines(filePath);
for (int i = 0; i < lines.Length; i++)
{
var line = lines[i];
if (string.Equals(line, @"#define ENABLE_CUSTOM_CRASH_REPORTER 0"))
{
lines[i] = @"#define ENABLE_CUSTOM_CRASH_REPORTER 1";
}
}
File.WriteAllLines(filePath, lines);
}
}
catch
{
throw;
}
}
}
I would add some debug logging there to figure out what is going on. Most likely that catch block is executing.
If you want to be able to debug locally, you can use the PostProcessBuildAttribute which should run both locally and on UCB. If you decide to go this route, make sure to remove the ‘Post-Export Method’ from your advanced settings on UCB.
I will try that next, but can you please check if you can tell what is wrong with this minimal code that fails as a post process method. I stripped everything out and just have a single empty method - and it still fails.
Is my class supposed to be static? Does my method need to return bool? Am I using some reserved names for class, method or path variable?
public class PostExport
{
public static void PostExportMethod(string ExportPath)
{
}
}
Can you check if I entered the name of the method correctly in UCB? The screenshot is attached to this message.
I am not sure I can figure out what I am doing incorrectly, but I suppose that this matter should have an example documented, so that others can understand it too.
Yes that all looks correct, except for the one thing I forgot to mention - the class needs to be in the Editor/ folder in your Assets. I will get the documentation updated to reflect this.
Am I missing something or there is something wrong. You are rerefering to a documentation. Where is it exactly may I ask? I only found 3 tutorials and nothing more. The documentation for Services is only in regards to Unity Analytics and Ads. Where should I look for Cloud Build docs?
Thanks
Edit:
Nevermind, now I see that after logging in I see the Support where the docs are located (https://build.cloud.unity3d.com/support/) But why there is no link in overall docs if other services are documented, as well as the landing page for Unity Cloud Build that can be accessed via main page Services tab? I wanted to read more about it to see if it can potentially solve some of the problems we are currently facing and it turned out that I had to sign up to find a link for docs.
Ok, I got the post process method work by using PostProcessBuildAttribute and placing it in Editor folder. Great.
Now I have another related problem.
I can’t seem to get the path to the file I would like to change in my post process method.
I want to open a file using File.ReadAllLines(filePath)
but I need to give it a path to that file.
I am trying to get the directory location of my exported files but I get empty value from
EditorUserBuildSettings.GetBuildLocation(target)
and the path that I get passed to my post process method gives me a path location string starting with /BUILD_PATH/.
How can I figure out what that BUILD_PATH value is?
Can I use that value somehow to check if my File.Exists()?
That path you receive via method arguments should be a valid one that points at your build location, i.e. the folder where your xcodeproj file is contained at root. There is a Cloud Build demo project here that uses a PostBuildProcessor.cs script to manipulate a project via the XCode Manipulation API, this may be useful for you as a reference.
See lines 50-53 of PostBuildProcessor.cs for a file read example: