Skip to content

Commit b4cb06a

Browse files
committed
Update iOS signed xcframeworks and Post Build
1 parent c42b106 commit b4cb06a

File tree

238 files changed

+523
-96764
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+523
-96764
lines changed

Editor/BacktraceXcodePostBuild.cs

Lines changed: 77 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,73 +10,109 @@
1010
namespace Backtrace.Unity.Editor.iOS
1111
{
1212
/// <summary>
13-
/// Links Backtrace.xcframework + CrashReporter.xcframework on UnityFramework,
14-
/// embeds and signs Backtrace (dynamic) in the app target, and sets Swift/iOS settings.
13+
/// Links Backtrace.xcframework and CrashReporter.xcframework
14+
/// embeds, signs Backtrace and sets Swift/iOS settings.
1515
/// </summary>
1616
public static class BacktraceXcodePostBuild
1717
{
18-
[PostProcessBuild(999)]
19-
public static void OnPostProcessBuild(BuildTarget target, string buildPath)
18+
// Runs late after post-processors
19+
private const int PostBuildOrder = 500;
20+
21+
[PostProcessBuild(PostBuildOrder)]
22+
public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
2023
{
21-
if (target != BuildTarget.iOS) return;
24+
if (buildTarget != BuildTarget.iOS) {
25+
return;
26+
}
2227

23-
var projPath = PBXProject.GetPBXProjectPath(buildPath);
24-
var proj = new PBXProject();
25-
proj.ReadFromFile(projPath);
28+
var projectPath = PBXProject.GetPBXProjectPath(buildPath);
29+
var project = new PBXProject();
30+
project.ReadFromFile(projectPath);
2631

2732
#if UNITY_2019_3_OR_NEWER
28-
string appTargetGuid = proj.GetUnityMainTargetGuid();
29-
string ufTargetGuid = proj.GetUnityFrameworkTargetGuid();
33+
string appTargetGuid = project.GetUnityMainTargetGuid();
34+
string unityFrameworkTargetGuid = project.GetUnityFrameworkTargetGuid();
3035
#else
31-
string appTargetGuid = proj.TargetGuidByName("Unity-iPhone");
32-
string ufTargetGuid = appTargetGuid;
36+
string appTargetGuid = project.TargetGuidByName("Unity-iPhone");
37+
string unityFrameworkTargetGuid = appTargetGuid;
3338
#endif
34-
// Find the xcframeworks that Unity copied into the export (regardless of folder)
35-
string FindXCFramework(string name)
39+
if (string.IsNullOrEmpty(appTargetGuid) || string.IsNullOrEmpty(unityFrameworkTargetGuid))
3640
{
37-
var dirs = Directory.GetDirectories(buildPath, name, SearchOption.AllDirectories);
38-
return dirs.FirstOrDefault();
41+
Debug.LogError("[Backtrace] iOS post-build: could not resolve Xcode targets.");
42+
return;
3943
}
4044

41-
var backtraceXC = FindXCFramework("Backtrace.xcframework");
42-
var crashXC = FindXCFramework("CrashReporter.xcframework");
45+
// Locate exported xcframeworks
46+
string FindXCFramework(string folderName)
47+
{
48+
var matches = Directory.GetDirectories(buildPath, folderName, SearchOption.AllDirectories);
49+
return matches.FirstOrDefault();
50+
}
4351

44-
if (string.IsNullOrEmpty(backtraceXC))
52+
var backtraceXCPath = FindXCFramework("Backtrace.xcframework");
53+
var crashReporterXCPath = FindXCFramework("CrashReporter.xcframework");
54+
55+
if (string.IsNullOrEmpty(backtraceXCPath))
4556
{
46-
Debug.LogError("[Backtrace] Could not locate Backtrace.xcframework in the exported Xcode project.");
57+
Debug.LogError($"[Backtrace] Could not locate Backtrace.xcframework under: {buildPath}");
4758
return;
4859
}
49-
if (string.IsNullOrEmpty(crashXC))
60+
if (string.IsNullOrEmpty(crashReporterXCPath))
5061
{
51-
Debug.LogError("[Backtrace] Could not locate CrashReporter.xcframework in the exported Xcode project.");
62+
Debug.LogError($"[Backtrace] Could not locate CrashReporter.xcframework under: {buildPath}");
5263
return;
5364
}
5465

55-
// Add files to project with paths relative to project
56-
string relBacktrace = backtraceXC.Replace(buildPath + "/", "");
57-
string relCrash = crashXC.Replace(buildPath + "/", "");
66+
// Project-relative paths
67+
string relBacktraceXC = ToProjectRelative(buildPath, backtraceXCPath);
68+
string relCrashReporterXC = ToProjectRelative(buildPath, crashReporterXCPath);
69+
70+
// Add file references
71+
string backtraceFileGuid = project.FindFileGuidByProjectPath(relBacktraceXC);
72+
if (string.IsNullOrEmpty(backtraceFileGuid)) {
73+
backtraceFileGuid = project.AddFile(relBacktraceXC, relBacktraceXC, PBXSourceTree.Source);
74+
}
75+
76+
string crashReporterFileGuid = project.FindFileGuidByProjectPath(relCrashReporterXC);
77+
if (string.IsNullOrEmpty(crashReporterFileGuid)) {
78+
crashReporterFileGuid = project.AddFile(relCrashReporterXC, relCrashReporterXC, PBXSourceTree.Source);
79+
}
5880

59-
string btGuid = proj.AddFile(relBacktrace, relBacktrace, PBXSourceTree.Source);
60-
string crGuid = proj.AddFile(relCrash, relCrash, PBXSourceTree.Source);
81+
// Linking
82+
project.AddFileToBuild(unityFrameworkTargetGuid, backtraceFileGuid);
83+
project.AddFileToBuild(unityFrameworkTargetGuid, crashReporterFileGuid);
6184

62-
// Link both on UnityFramework
63-
proj.AddFileToBuild(ufTargetGuid, btGuid);
64-
proj.AddFileToBuild(ufTargetGuid, crGuid);
85+
// Embedding
86+
PBXProjectExtensions.AddFileToEmbedFrameworks(project, appTargetGuid, backtraceFileGuid);
87+
AddBuildPropertyUnique(project, appTargetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited)");
88+
AddBuildPropertyUnique(project, appTargetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");
6589

66-
// Embed Backtrace (dynamic) on the app target
67-
PBXProjectExtensions.AddFileToEmbedFrameworks(proj, appTargetGuid, btGuid);
68-
proj.AddBuildProperty(appTargetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
90+
// iOS settings
91+
project.SetBuildProperty(appTargetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
92+
project.SetBuildProperty(appTargetGuid, "IPHONEOS_DEPLOYMENT_TARGET", "13.0");
93+
project.SetBuildProperty(unityFrameworkTargetGuid, "IPHONEOS_DEPLOYMENT_TARGET", "13.0");
6994

70-
// Swift / platform settings (SDK requires iOS 13+)
71-
proj.SetBuildProperty(appTargetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
72-
proj.SetBuildProperty(appTargetGuid, "IPHONEOS_DEPLOYMENT_TARGET", "13.0");
73-
proj.SetBuildProperty(ufTargetGuid, "IPHONEOS_DEPLOYMENT_TARGET", "13.0");
95+
// Obj-C Linker Flag
96+
AddBuildPropertyUnique(project, unityFrameworkTargetGuid, "OTHER_LDFLAGS", "-ObjC");
7497

75-
// Recommended & safe for Obj-C categories
76-
proj.AddBuildProperty(ufTargetGuid, "OTHER_LDFLAGS", "-ObjC");
98+
project.WriteToFile(projectPath);
99+
Debug.Log("[Backtrace] iOS post-build: frameworks linked/embedded. Swift stdlib enabled.");
100+
}
101+
102+
private static string ToProjectRelative(string buildPath, string absolutePath)
103+
{
104+
var rel = absolutePath.Replace('\\', '/');
105+
var root = (buildPath + "/").Replace('\\', '/');
106+
return rel.StartsWith(root) ? rel.Substring(root.Length) : rel;
107+
}
77108

78-
proj.WriteToFile(projPath);
79-
Debug.Log("[Backtrace] iOS post-build: frameworks linked/embedded; Swift stdlib enabled; iOS 13.0 set.");
109+
private static void AddBuildPropertyUnique(PBXProject proj, string targetGuid, string key, string value)
110+
{
111+
var current = proj.GetBuildPropertyForAnyConfig(targetGuid, key);
112+
if (current == null || !current.Split(' ').Contains(value))
113+
{
114+
proj.AddBuildProperty(targetGuid, key, value);
115+
}
80116
}
81117
}
82118
}

iOS/Backtrace.xcframework.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iOS/Backtrace.xcframework/Info.plist

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,6 @@
44
<dict>
55
<key>AvailableLibraries</key>
66
<array>
7-
<dict>
8-
<key>BinaryPath</key>
9-
<string>Backtrace.framework/Backtrace</string>
10-
<key>DebugSymbolsPath</key>
11-
<string>dSYMs</string>
12-
<key>LibraryIdentifier</key>
13-
<string>tvos-arm64</string>
14-
<key>LibraryPath</key>
15-
<string>Backtrace.framework</string>
16-
<key>SupportedArchitectures</key>
17-
<array>
18-
<string>arm64</string>
19-
</array>
20-
<key>SupportedPlatform</key>
21-
<string>tvos</string>
22-
</dict>
237
<dict>
248
<key>BinaryPath</key>
259
<string>Backtrace.framework/Backtrace</string>
@@ -36,25 +20,6 @@
3620
<key>SupportedPlatform</key>
3721
<string>ios</string>
3822
</dict>
39-
<dict>
40-
<key>BinaryPath</key>
41-
<string>Backtrace.framework/Versions/A/Backtrace</string>
42-
<key>DebugSymbolsPath</key>
43-
<string>dSYMs</string>
44-
<key>LibraryIdentifier</key>
45-
<string>ios-arm64_x86_64-maccatalyst</string>
46-
<key>LibraryPath</key>
47-
<string>Backtrace.framework</string>
48-
<key>SupportedArchitectures</key>
49-
<array>
50-
<string>arm64</string>
51-
<string>x86_64</string>
52-
</array>
53-
<key>SupportedPlatform</key>
54-
<string>ios</string>
55-
<key>SupportedPlatformVariant</key>
56-
<string>maccatalyst</string>
57-
</dict>
5823
<dict>
5924
<key>BinaryPath</key>
6025
<string>Backtrace.framework/Backtrace</string>
@@ -74,42 +39,6 @@
7439
<key>SupportedPlatformVariant</key>
7540
<string>simulator</string>
7641
</dict>
77-
<dict>
78-
<key>BinaryPath</key>
79-
<string>Backtrace.framework/Backtrace</string>
80-
<key>DebugSymbolsPath</key>
81-
<string>dSYMs</string>
82-
<key>LibraryIdentifier</key>
83-
<string>tvos-arm64_x86_64-simulator</string>
84-
<key>LibraryPath</key>
85-
<string>Backtrace.framework</string>
86-
<key>SupportedArchitectures</key>
87-
<array>
88-
<string>arm64</string>
89-
<string>x86_64</string>
90-
</array>
91-
<key>SupportedPlatform</key>
92-
<string>tvos</string>
93-
<key>SupportedPlatformVariant</key>
94-
<string>simulator</string>
95-
</dict>
96-
<dict>
97-
<key>BinaryPath</key>
98-
<string>Backtrace.framework/Versions/A/Backtrace</string>
99-
<key>DebugSymbolsPath</key>
100-
<string>dSYMs</string>
101-
<key>LibraryIdentifier</key>
102-
<string>macos-arm64_x86_64</string>
103-
<key>LibraryPath</key>
104-
<string>Backtrace.framework</string>
105-
<key>SupportedArchitectures</key>
106-
<array>
107-
<string>arm64</string>
108-
<string>x86_64</string>
109-
</array>
110-
<key>SupportedPlatform</key>
111-
<string>macos</string>
112-
</dict>
11342
</array>
11443
<key>CFBundlePackageType</key>
11544
<string>XFWK</string>
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)