Open SergeiEfimik opened 2 years ago
@SergeiEfimik Thanks for reporting, I can confirm this issue on Windows when using Unity's build iOS option. This is not an issue on macOS.
We have a fixed this issue and it will be included in the next update in PR #493. In the mean time you can work around the issue by building on macOS.
Thanks for reply!
The problem is still on the version 3.0.2. The build on iOS runs correctly, the Entitlements.entitlements file is created as needed. But when publishing in xCode - error with code 90206. Error 90206 is solved by setting "Always Embed Swift Standard Libraries" to "true" for Unity-iPhone project and "false" value for UnityFramework and OneSignalNotificationServiceExtension.
@SergeiEfimik Thanks for reporting this, we addressed this PR #501 so the "Always Embed Swift Standard Libraries" should be set to false for all targets by default now in the OneSignal-Unity-SDK 3.0.2. I would recommend doing a clean build from Unity as well as Xcode ensure the old setting is not carrying over.
@jkasten2 Maybe you have a version of BuildPostProcessor.cs where the problem with the entitlements file for building on Windows for iOS target is solved?
@SergeiEfimik Can you double check the iOS part of the OneSignal SDK is on 3.0.2 as well as core?
If this is all up to date can you include the exact version of Unity you are using?
I have confirmed the issue no longer happens on Unity 2020.3.30f1 on Windows 11.
@jkasten2 Windows 10 Pro 21H2, Unity 2021.3.2 LTS, External Dependency Manager 1.2.171. Before installing OneSignal, I deleted folders Library, obj, Logs from project directory. Installed with scoped registries. Also tried installing OneSignal via unitypackage - same error for version 3.0.0, 3.0.1, 3.0.2. All the same, but with version 2.14.6 - build complete without entitlements error. I checked also on an empty project - build complete without errors, but Entitlements.entitlements file in build directory not created.
I think I've found the source of the problem. Apparently there is a conflict with the code responsible for native authorization through AppleID. My project has this script:
#if UNITY_IOS || UNITY_TVOS
#define UNITY_XCODE_EXTENSIONS_AVAILABLE
#endif
using UnityEditor;
using UnityEditor.Callbacks;
using AppleAuth.Editor;
#if UNITY_XCODE_EXTENSIONS_AVAILABLE
using UnityEditor.iOS.Xcode;
#endif
namespace MyProject.PostBuild
{
public static class SignInWithApplePostprocessor
{
[PostProcessBuild(1)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
if (target == BuildTarget.iOS || target == BuildTarget.tvOS)
{
#if UNITY_XCODE_EXTENSIONS_AVAILABLE
var projectPath = PBXProject.GetPBXProjectPath(path);
#if UNITY_2019_3_OR_NEWER
var project = new PBXProject();
project.ReadFromString(System.IO.File.ReadAllText(projectPath));
var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", null, project.GetUnityMainTargetGuid());
manager.AddSignInWithApple();
manager.WriteToFile();
#else
var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", PBXProject.GetUnityTargetName());
manager.AddSignInWithAppleWithCompatibility();
manager.WriteToFile();
#endif
#endif
}
else if (target == BuildTarget.StandaloneOSX)
{
AppleAuthMacosPostprocessorHelper.FixManagerBundleIdentifier(target, path);
}
}
}
}
As I wrote above, when importing OneSignal into an empty project, the "Entitlements.entitlements" file is not created in the root directory. Instead, a "OneSignalNotificationServiceExtension.entitlements" file is created in the "OneSignalNotificationServiceExtension" folder. But I can't figure out why there is a conflict between the entitlements files in my project with the script above.
I replase [PostProcessBuild(1)] index 1 on int.MaxValue: [PostProcessBuild(int.MaxValue)] - build complete without errors. But this is in an empty project with imported AppleAuth from my project. In my source project, changing the index did not fix the error. I will continue to try and look for more options.
@SergeiEfimik
Thanks for the Unity version. With the OneSignal SDK 3.0.2 do you see a different error when building on Windows now? Do you only get an error when you add your SignInWithApplePostprocessor
? Can you share your new full error as well?
Could you share where you got the code for SignInWithApplePostprocessor
from? Or the documentation you used to create it if it is something you created?
Are you still seeing this error on OneSignal 3.0.2? If so are you using the same Unity version on macOS to build? Also what version of Xcode are you using?
@jkasten2 About 90206: yes, error still in version 3.0.2 + xCode 13.1 (13A1030d). I tried to build the project both on one platform (Windows and Mac) on target iOS - result is the same (same settings "Always Embed Swift Standard Libraries"). Should "Enable Swift Framework Support Workaround" checkbox be enabled in iOS Resolver Settings (External Dependency Manager 1.2.171)?
About Entitlements. Found out the cause of the problem. I am using Mobile Notifications Unity-package to get DeviceToken on iOS. If disable push notification in project settings, then build on Windows complete correctly. At the same time, notifications from OneSignal received as expected.
But now I can't get DeviceToken (required "Enable Push Notification").
I get the same issue, when having another PostProcessor script running prior to the OneSignal PostProcessor. I think the issue lies in the GetEntitlementsPath method. It returns the fullpath to the entitlement file when the file already exists (which is the case when there is another PostProcessor adding this file).
Then ProjectCapabilityManager.WriteToFile combines this fullpath with the buildpath leading to a faulty path.
A temporary fix for me is to make sure that this PostProcessor script is running first by changing the callbackOrder on my other PostProcessor script.
@pettersaiteppeland, I wrote above that I changed callbackOrder from 1 to int.MaxValue, but this did not solve my problem. Perhaps when Mobile Notifications are enabled (see screenshot above), Unity automatically creates an entitlement file before OneSignal is processed.
@SergeiEfimik Strange, you could try to attach a breakpoint in AddProjectCapabilities and confirm that the entitlement file already exists or not. When it does not exist, it should work.
@pettersaiteppeland How to do it right? My VS doesn't switch to Degug mode while building a project in Unity.
@SergeiEfimik I am not familiar with VS unfortunately, Rider is my IDEA. When the debugger is attached, the build stops at breakpoints. Hmm, you could embed the package and add custom log entries to find more information perhaps?
@pettersaiteppeland It turned out to start the debug mode. At OneSignal build time, there is already a game.entitlements file.
When Unity Mobile Notifications are disabled, file "game.entitlements" is not created.
@SergeiEfimik Yes, we are in the same boat then. GetEntitlementsPath is returning the fullpath which is not working with ProjectCapabilityManager.WriteToFile.
What happened?
The build is successful, but in the Unity console the error "Could not find a part of the path... Entitlements.entitlements" (see "Relevant log output" for full details). File "Entitlements.entitlements" is created, but its content is smaller than in file created in SDK version 2.14.6.
When opening a built project (.xworkspace) in xCode on Mac, it writes an error: The file "/Users/work/MyProject/iOS/C:/Unity3d/MyProject/Builds/iOS/Entitlements.entitlements" could not be opened. Verify the value of the CODE_SIGN_ENTITLEMENTS build setting for target "Unity-iPhone" is correct and that the file exists on disk.
Оn version 2.14.6 everything works correctly on iOS and Android. On version 3.0.1 and 3.0.0 work only on Android. Copying the contents of the Entitlements.entitlements file from 2.14.6 to the new one does not solve the problem, the error in xCode remains the same.
Steps to reproduce?
What did you expect to happen?
Build with correctrly Entitlements.entitlements file for iOS on Windows
Unity version
2021.3.0f1
OneSignal Unity SDK version
3.0.1, 3.0.0
Platform
Windows
Relevant log output
Code of Conduct