Skip to content

Instantly share code, notes, and snippets.

@tenpn
Forked from capyvara/gist:5230032
Last active January 11, 2016 06:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenpn/f8da1b7df7352a1d50ff to your computer and use it in GitHub Desktop.
Save tenpn/f8da1b7df7352a1d50ff to your computer and use it in GitHub Desktop.
SymolicationEnabler unity post-processor
/*
The MIT License (MIT)
Copyright (c) 2014 Andrew Fray, Marcelo Oliveira
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System.IO;
// unity builds by default don't include info to symbolicate iOS crashes.
// this post-processor turns on some flags to enable that.
// https://github.com/agentsim/Symbolicator
// http://www.markj.net/ios-crash-reports-unity3d-symbolicate/
class SymbolicationEnabler
{
#if UNITY_IPHONE
[PostProcessBuild(1400)] // near the end
public static void OnPostProcessBuild(BuildTarget target, string path)
{
if (target != BuildTarget.iPhone) {
return; // How did we get here?
}
// Adjust dSYM generation
var xcodeProjectPath = Path.Combine(path, "Unity-iPhone.xcodeproj");
var pbxPath = Path.Combine(xcodeProjectPath, "project.pbxproj");
var sb = new System.Text.StringBuilder();
var xcodeProjectLines = File.ReadAllLines(pbxPath);
foreach (var line in xcodeProjectLines) {
// Remove from OTHER_LDFLAGS
if (line.Contains("-Wl,-S,-x")) {
continue;
}
// iOS Default when not present is dwarf-with-dsym
if (line.Contains("DEBUG_INFORMATION_FORMAT")) {
// Replace line to stripping on postprocess deployment flags
sb.AppendLine("\t\t\t\tDEPLOYMENT_POSTPROCESSING = YES;");
sb.AppendLine("\t\t\t\tSEPARATE_STRIP = YES;");
sb.AppendLine("\t\t\t\tSTRIP_INSTALLED_PRODUCT = YES;");
continue;
}
// Defaults to Yes
if (line.Contains("COPY_PHASE_STRIP")) {
continue;
}
// Defaults to Yes
if (line.Contains("GCC_GENERATE_DEBUGGING_SYMBOLS")) {
continue;
}
sb.AppendLine(line);
}
File.WriteAllText(pbxPath, sb.ToString());
}
#endif
}
@MrTact
Copy link

MrTact commented Dec 26, 2014

Question: Why do this with text processing rather than use Unity's Xcode API? (I guess a reasonable argument could be made that Unity doesn't ship with the API yet, so you didn't want to require a separate download.)

@tenpn
Copy link
Author

tenpn commented Jan 6, 2015

Two reasons:

  • I didn't know about unity's xcode API when I did this, but yeah even if I did, it not being built-in ruins the gist-ness of this
  • I didn't write the inner code, I lifted it from another gist (linked above), I just wrapped it in a build post-processor. I don't claim to really understand it enough to re-write it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment