OneSignal / OneSignal-Unity-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Unity app with OneSignal. https://onesignal.com
Other
222 stars 61 forks source link

[Bug]: Dependency Cycle Error after Updating to Xcode 15 #651

Open shaiArn opened 1 year ago

shaiArn commented 1 year ago

What happened?

Hello OneSignal Unity SDK team,

I recently upgraded to Xcode version 15 and faced an issue while building my project. The error details are below.

Interestingly, a similar issue appears to be occurring with Flutter iOS builds as well. You can find a related discussion here: https://stackoverflow.com/questions/77138968/handling-cycle-inside-runner-building-could-produce-unreliable-results-after-up

While the solution provided in the above Stack Overflow thread does work, it isn't a viable long-term fix for us. The manual intervention it requires disrupts our CI/CD system.

I hope this information aids in diagnosing the issue. If there are any additional details or clarifications needed, please let me know.

Thank you for your attention and support.

Steps to reproduce?

1. Update to Xcode 15
2. Build a Unity project that uses OneSignal SDK for iOS
3. Build an iOS build from Xcode

What did you expect to happen?

The build process to work smoothly without manual changes to Build Phase.

Unity version

2021.3.23f1 (LTS)

OneSignal Unity SDK version

3.0.1

Platform

iOS

Relevant log output

Showing All Messages
Cycle inside Unity-iPhone; building could produce unreliable results.
Cycle details:
→ Target 'Unity-iPhone': CodeSign Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app
○ That command depends on command in Target 'Unity-iPhone': script phase “[CP] Embed Pods Frameworks”
○ Target 'Unity-iPhone' has copy command from 'Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/BuildProductsPath/Release-iphoneos/OneSignalNotificationServiceExtension.appex' to 'Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/PlugIns/OneSignalNotificationServiceExtension.appex'
○ That command depends on command in Target 'Unity-iPhone': script phase “Unity Process symbols”
○ Target 'Unity-iPhone' has a command with output 'Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/BuildProductsPath/Release-iphoneos/<appName>.app.dSYM'
○ Target 'Unity-iPhone' has process command with output 'Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/Info.plist'
○ Target 'Unity-iPhone' has copy command from 'Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/BuildProductsPath/Release-iphoneos/OneSignalNotificationServiceExtension.appex' to 'Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/PlugIns/OneSignalNotificationServiceExtension.appex'

Raw dependency cycle trace:

target:  ->

node: <all> ->

command: <all> ->

node: Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/_CodeSignature ->

command: P0:target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f-:Release:CodeSign Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app ->

node: Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/Frameworks/FBAEMKit.framework/ ->

directoryTreeSignature: � ->

directoryContents: Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/Frameworks/FBAEMKit.framework ->

node: Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/Frameworks/FBAEMKit.framework ->

command: P2:target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f-:Release:PhaseScriptExecution [CP] Embed Pods Frameworks Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/IntermediateBuildFilesPath/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/Script-7D8413102D645D53E8525294.sh ->

node: Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/IntermediateBuildFilesPath/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/Script-7D8413102D645D53E8525294.sh ->

command: P2:target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f-:Release:WriteAuxiliaryFile Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/IntermediateBuildFilesPath/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/Script-7D8413102D645D53E8525294.sh ->

node: <target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f--fused-phase7-copy-files> ->

command: P0:::Gate target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f--fused-phase7-copy-files ->

node: <Copy Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/PlugIns/OneSignalNotificationServiceExtension.appex> ->

CYCLE POINT ->

command: P0:target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f-:Release:Copy Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/PlugIns/OneSignalNotificationServiceExtension.appex Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/BuildProductsPath/Release-iphoneos/OneSignalNotificationServiceExtension.appex ->

node: <target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f--fused-phase6-symbolupload> ->

command: P0:::Gate target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f--fused-phase6-symbolupload ->

node: Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/IntermediateBuildFilesPath/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/Script-685842A99628018F8EEBB260.sh ->

command: P2:target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f-:Release:WriteAuxiliaryFile Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/IntermediateBuildFilesPath/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/Script-685842A99628018F8EEBB260.sh ->

node: <target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f--fused-phase5-unity-process-symbols> ->

command: P0:::Gate target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f--fused-phase5-unity-process-symbols ->

node: <execute-shell-script-4d46f0999f4e53d6791a1877ccf164d70c3f1bba89277f759c6becf1eeb525a1-target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f-> ->

command: P2:target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f-:Release:PhaseScriptExecution Unity Process symbols Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/IntermediateBuildFilesPath/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/Script-75414130B284C3C5FE31AD75.sh ->

node: Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/BuildProductsPath/Release-iphoneos/<appName>.app.dSYM/Contents/Resources/DWARF/<appName>/ ->

directoryTreeSignature: � ->

directoryContents: Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/BuildProductsPath/Release-iphoneos/<appName>.app.dSYM/Contents/Resources/DWARF/<appName> ->

node: Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/BuildProductsPath/Release-iphoneos/<appName>.app.dSYM/Contents/Resources/DWARF/<appName> ->

command: P0:target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f-:Release:GenerateDSYMFile Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/BuildProductsPath/Release-iphoneos/<appName>.app.dSYM Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/<appName> ->

node: Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/Info.plist ->

command: P0:target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f-:Release:ProcessInfoPlistFile Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/Info.plist Users/user/Documents/unity__builds/<dir_name>/Info.plist ->

node: Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/PlugIns/OneSignalNotificationServiceExtension.appex ->

command: P0:target-Unity-iPhone-4d46f0999f4e53d6791a1877ccf164d70fa8628908142c1784945aff676e527f-:Release:Copy Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/<appName>.app/PlugIns/OneSignalNotificationServiceExtension.appex Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-ewzqhutllyvbawgwbzvdccarkzxg/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/BuildProductsPath/Release-iphoneos/OneSignalNotificationServiceExtension.appex

Code of Conduct

emawby commented 1 year ago

@shaiArn This looks like a wonky interaction between Unity(or Flutter), Cocoapods, and the fact that your app has a Notification Service Extension. I doubt this is something that can be solved by a change in the SDK, but we can investigate workarounds/setup steps that will resolve the issue.

MTPirate89 commented 1 year ago

Have same issue after upgrading to Xcode version 15 Unity verstion 2021.3.31f1 (LTS) OneSignal Unity SDK version https://github.com/OneSignal/OneSignal-Unity-SDK/releases/tag/3.0.11

Xcode project is generated on each player build. So we need some workaround that can be implemented in PostBuild

Update: found on Unity Forum that they are currently working on fix https://forum.unity.com/threads/xcode-15-cycle-inside-unity-iphone-building-could-produce-unreliable-results.1496747/

Trunksome commented 1 year ago

I had the same issue, and got it to build by changing the order of the build phases.

Move "Embed App Extensions" of the main target to be before "Unity Process symbols for Unity-iPhone".

image

Hope this helps! Almost pulled my hair out over this one.

shepherd-l commented 1 year ago

I was unable to reproduce the error in a new project with OneSignal. Could any of you provide a sample project that reproduces the error along with what Unity version and OneSignal SDK version you used?

arrwhidev commented 1 year ago

We're experiencing the same issue. I don't have a project, but I will chip in with some extra detail...

Unfortunately for us, whilst the re-ordering fix does fix the "cycle error" and the app does build, it immediately crashes when it runs on the device due to:

Error loading /var/containers/Bundle/Application/<REDACTED>/Frameworks/UnityFramework.framework/UnityFramework 
(143):  dlopen(/var/containers/Bundle/Application/<REDACTED>/Frameworks/UnityFramework.framework/UnityFramework, 0x0109): 
Library not loaded: @rpath/AppleCoreNative.framework/AppleCoreNative
...

It's not clear to me if the re-ordering fix is actually fixing it, or if it is just plastering over one issue and causing this second issue. This second issue could be a total non-issue, in reality.

Similarly to others, this started when we tried to upgrade to XCode 15 to support iOS17, no issues prior to this.

Perhaps older version of XCode were more lenient/flexible but 15 is more strict, which is why a bunch of people are seeing this issue (I've seen it around a few forums). Even though it might not be a OneSignal issue directly, clearly there's a certain project structure that is susceptible to this issue, if we can collectively find a solution that would be great.

flashmandv commented 12 months ago

Hello, Is there any update on the cycle error? As it also happened to me using latest Xcode 15.0.1 and latest OneSignal for Unity. The workaround does solve the compiling error but I'm not sure if production build will be stable enough

AthanasiosGrigoroudis commented 9 months ago

This issue is still happening with Xcode 15.2 and the latest OneSignal version and we're currently blocked from building our game. The workaround works but I haven't figured out how to automate it on post process. Does anyone have a temporary solution that works automatically?

AthanasiosGrigoroudis commented 9 months ago

Updating the Unity version from 2021.3 to 2022.3 fixed it for me

xinatcg commented 9 months ago

same issue, Is there any workaround for unity 2021?

xinatcg commented 9 months ago

find a solution by using this code with minor change: https://forum.unity.com/threads/xcode-15-cycle-inside-unity-iphone-building-could-produce-unreliable-results.1496747/#post-9397949

namespace YourNameSpace
{
    internal static class FixBuildPhasesOrderForUnityIPhone
    {
        private const string _sectionSearchKey = "Build configuration list for PBXNativeTarget \"Unity-iPhone\"";
        private const string _targetBuildPhaseKey = "ShellScript";  // changed from original post

        [PostProcessBuild(45)]
        private static void FixBuildPhasesOrderInProject(BuildTarget target, string pathToBuiltProject)
        {
            if (target != BuildTarget.iOS)
            {
                return;
            }

            // Search for order array.
            var path = Path.Combine(pathToBuiltProject, "Unity-iPhone.xcodeproj", "project.pbxproj");
            var allLines = File.ReadAllLines(path);

            // Search for first line.
            var firstLine = -1;
            for (var i = 0; i + 2 < allLines.Length; i++)
            {
                if (allLines[i].Contains(_sectionSearchKey) && allLines[i + 1].Contains("buildPhases = ("))
                {
                    firstLine = i + 2;
                    break;
                }
            }

            // Check for error.
            if (firstLine <= 0)
            {
                return;
            }

            // Search for last line.
            var lastLine = -1;
            for (var i = firstLine; i + 1 < allLines.Length && i - firstLine < 30; i++)
            {
                if (allLines[i + 1].Contains(");"))
                {
                    lastLine = i;
                    break;
                }
            }

            // Check for error.
            if (lastLine <= 0 || lastLine == firstLine)
            {
                return;
            }

            var buffer = [new](http://www.google.com/search?q=new+msdn.microsoft.com) List<string>();
            for (var i = firstLine; i <= lastLine; i++)
            {
                buffer.Add(allLines[i]);
            }

            var index = buffer.FindIndex(x => x.Contains(_targetBuildPhaseKey));
            if (index == -1)
            {
                return;
            }

            var line = buffer[index];
            buffer.RemoveAt(index);
            buffer.Add(line);

            // Replace old lines with new ones.
            for (var i = 0; i < buffer.Count; i++)
            {
                allLines[firstLine + i] = buffer[i];
            }

            // Save results.
            File.WriteAllLines(path, allLines);
            Debug.Log("BuildPhases order were reordered in xCode project.");
        }
    }
}

The build phases change from

image

to

image
Trunksome commented 8 months ago

I noticed something interesting: when I build the xcode project on Windows and then run it on my Mac, I'm getting the dependency cycle error and need to shift around the build phases. When I build the xcode project with Unity running on my Mac, I can build just fine without having to touch the build phases.

DavidJaksztaST commented 8 months ago

find a solution by using this code with minor change: https://forum.unity.com/threads/xcode-15-cycle-inside-unity-iphone-building-could-produce-unreliable-results.1496747/#post-9397949

namespace YourNameSpace
{
    internal static class FixBuildPhasesOrderForUnityIPhone
    {
        private const string _sectionSearchKey = "Build configuration list for PBXNativeTarget \"Unity-iPhone\"";
        private const string _targetBuildPhaseKey = "ShellScript";  // changed from original post

        [PostProcessBuild(45)]
        private static void FixBuildPhasesOrderInProject(BuildTarget target, string pathToBuiltProject)
        {
            if (target != BuildTarget.iOS)
            {
                return;
            }

            // Search for order array.
            var path = Path.Combine(pathToBuiltProject, "Unity-iPhone.xcodeproj", "project.pbxproj");
            var allLines = File.ReadAllLines(path);

            // Search for first line.
            var firstLine = -1;
            for (var i = 0; i + 2 < allLines.Length; i++)
            {
                if (allLines[i].Contains(_sectionSearchKey) && allLines[i + 1].Contains("buildPhases = ("))
                {
                    firstLine = i + 2;
                    break;
                }
            }

            // Check for error.
            if (firstLine <= 0)
            {
                return;
            }

            // Search for last line.
            var lastLine = -1;
            for (var i = firstLine; i + 1 < allLines.Length && i - firstLine < 30; i++)
            {
                if (allLines[i + 1].Contains(");"))
                {
                    lastLine = i;
                    break;
                }
            }

            // Check for error.
            if (lastLine <= 0 || lastLine == firstLine)
            {
                return;
            }

            var buffer = [new](http://www.google.com/search?q=new+msdn.microsoft.com) List<string>();
            for (var i = firstLine; i <= lastLine; i++)
            {
                buffer.Add(allLines[i]);
            }

            var index = buffer.FindIndex(x => x.Contains(_targetBuildPhaseKey));
            if (index == -1)
            {
                return;
            }

            var line = buffer[index];
            buffer.RemoveAt(index);
            buffer.Add(line);

            // Replace old lines with new ones.
            for (var i = 0; i < buffer.Count; i++)
            {
                allLines[firstLine + i] = buffer[i];
            }

            // Save results.
            File.WriteAllLines(path, allLines);
            Debug.Log("BuildPhases order were reordered in xCode project.");
        }
    }
}

The build phases change from

image

to

image

can you explain what exactly you need to change to move Unity process symbols to the very end?