Skip to content

Instantly share code, notes, and snippets.

@dimmduh
Created February 3, 2017 03:55
Show Gist options
  • Save dimmduh/f2d33246aedb1ca398a3901c63ee39c6 to your computer and use it in GitHub Desktop.
Save dimmduh/f2d33246aedb1ca398a3901c63ee39c6 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
#if UNITY_IPHONE || UNITY_STANDALONE_OSX
using UnityEditor.iOS.Xcode;
#endif
using System.IO;
using System.Collections;
/// <summary>
/// Postprocess build player for Metrica.
/// See https://bitbucket.org/Unity-Technologies/iosnativecodesamples/src/ae6a0a2c02363d35f954d244a6eec91c0e0bf194/NativeIntegration/Misc/UpdateXcodeProject/
/// </summary>
public class PostprocessBuildPlayerAppMetrica
{
private static readonly string[] StrongFrameworks = {
"SystemConfiguration",
"UIKit",
"Foundation",
"CoreTelephony",
"CoreLocation",
"CoreGraphics",
"AdSupport",
"Security"
};
private static readonly string[] WeakFrameworks = {
"SafariServices"
};
private static readonly string[] Libraries = {
"z",
"sqlite3",
"c++"
};
private static readonly string[] LDFlags = {
"-ObjC"
};
#if UNITY_IPHONE || UNITY_STANDALONE_OSX
[PostProcessBuild]
public static void OnPostprocessBuild (BuildTarget buildTarget, string path)
{
#if UNITY_5
var expectedTarget = BuildTarget.iOS;
#else
var expectedTarget = BuildTarget.iPhone;
#endif
if (buildTarget == expectedTarget) {
var projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
var project = new PBXProject ();
project.ReadFromString (File.ReadAllText (projectPath));
var target = project.TargetGuidByName ("Unity-iPhone");
foreach (var frameworkName in StrongFrameworks) {
project.AddFrameworkToProject (target, frameworkName + ".framework", false);
}
foreach (var frameworkName in WeakFrameworks) {
project.AddFrameworkToProject (target, frameworkName + ".framework", true);
}
foreach (var flag in LDFlags) {
project.AddBuildProperty (target, "OTHER_LDFLAGS", flag);
}
foreach (var libraryName in Libraries) {
project.AddBuildProperty (target, "OTHER_LDFLAGS", "-l" + libraryName);
}
File.WriteAllText (projectPath, project.WriteToString ());
}
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment