Search Unity

Bug Apple Unity Plugins crashing on authentication

Discussion in 'iOS and tvOS' started by volkan-aydinli, Jun 19, 2023.

  1. volkan-aydinli

    volkan-aydinli

    Joined:
    Apr 8, 2018
    Posts:
    1
    Hello,

    I have implemented the apple's unity plugins so i can use player's game center informations to log in them. I followed the instructions on https://github.com/apple/unityplugins and using Apple.Core and Apple.GameKit in my game. On my start scene i am calling the authentication method like "var player = await GKLocalPlayer.Authenticate();" and it is crashing the app immediately. i have tested through testflight and also ran the application through xcode, it is the same. The error i got from xcode is going like this

    [B]023-06-19 15:07:54.991987+0300 [B]GameName[/B][23524:6527433] [general] Error loading /var/containers/Bundle/Application/43C0628B-8BE1-4C04-9273-F9A5D1F2750E/GameName.app/Frameworks/UnityFramework.framework/UnityFramework (146):  dlopen(/var/containers/Bundle/Application/43C0628B-8BE1-4C04-9273-F9A5D1F2750E/[B]GameName[/B].app/Frameworks/UnityFramework.framework/UnityFramework, 0x0109): Library not loaded: @rpath/AppleCoreNative.framework/AppleCoreNative[/B]

    [B] Referenced from: <135CE991-5878-3356-855B-0EE3A58465F7> /private/var/containers/Bundle/Application/43C0628B-8BE1-4C04-9273-F9A5D1F2750E/[B]GameName.[/B]app/Frameworks/UnityFramework.framework/UnityFramework[/B]

    [B] Reason: tried: '/usr/lib/swift/AppleCoreNative.framework/AppleCoreNative' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/AppleCoreNative.framework/AppleCoreNative' (no such file), '/usr/lib/swift/AppleCoreNative.framework/AppleCoreNative' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/AppleCoreNative.framework/AppleCoreNative' (no such file), '/private/var/containers/Bundle/Application/43C0628B-8BE1-4C04-9273-F9A5D1F2750E/The [B]GameName.[/B]app/Frameworks/AppleCoreNative.framework/AppleCoreNative' (no such file), '/usr/lib/swift/AppleCoreNative.framework/AppleCoreNative' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/AppleCoreNative.framework/AppleCoreNative' (no such file), '/usr/lib/swift/AppleCoreNative.framework/AppleCoreNative' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/AppleCoreNative.framework/AppleCoreNative' (no such file), '/private/var/containers/Bundle/Application/43C0628B-8BE1-4C04-9273-F9A5D1F2750E/[B]GameName[/B].app/Frameworks/AppleCoreNative.framework/AppleCoreNative' (no such file), '/private/var/containers/Bundle/Application/43C0628B-8BE1-4C04-9273-F9A5D1F2750E/[B]GameName[/B].app/Frameworks/AppleCoreNative.framework/AppleCoreNative' (no such file), '/System/Library/Frameworks/AppleCoreNative.framework/AppleCoreNative' (no such file, not in dyld cache)[/B]



    Has anyone experienced an error like this? I couldn't find any related example on the internet specific to these plugins so i am really open to any ideas right now.
     
  2. mmhouston6

    mmhouston6

    Joined:
    Aug 13, 2018
    Posts:
    2
    I had the same issue. I was able to get past that error but then got the same error just with the GameKitWrapper Framework instead. I tried manually adding Frameworks, it did not work. Gave up and used the Sign In With Apple Unity plugin instead. Super annoying and wasted time. I hope they fix this or someone knows a solution.
     
  3. vengefullfoot

    vengefullfoot

    Joined:
    Sep 24, 2018
    Posts:
    31
    Same error here, tried everything at Xcode level, not much success...
    It must be linked with the version of Unity (2022.3.3f1 in my case)
     
  4. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    811
  5. Telesto26

    Telesto26

    Joined:
    Dec 31, 2020
    Posts:
    13
    We also facing the same issue, any suggestions?
     
  6. kogi_rc

    kogi_rc

    Joined:
    Apr 23, 2019
    Posts:
    39
    Exactly same issue. It doesn't seem to be related to MousePods link but it sucks to hear that the plugin will not work even if we manage to fix the library linking problem.

    Update: Using this PR branch as base, then merging fixes from here and compiling it with included build script using 2020.3.33f1 Unity fixed above errors. Runtime testing is still ahead of me but at least it compiles and doesn't crash at the first sight of GK methods during runtime.
     
    Last edited: Jul 17, 2023
  7. Telesto26

    Telesto26

    Joined:
    Dec 31, 2020
    Posts:
    13
    @kogi_rc Is it possible to share the merged branch? We are stuck in this issue for weeks! Thanks.
     
  8. kogi_rc

    kogi_rc

    Joined:
    Apr 23, 2019
    Posts:
    39
    I can't share the branch but I can share commands to create it:
    Code (CSharp):
    1. git clone https://github.com/dodgy-ltd/apple-unityplugins.git
    2. cd .\apple-unityplugins
    3. git remote add muzzkat https://github.com/muZZkat/unityplugins.git
    4. git fetch muzzkat
    5. git merge muzzkat/muzzkat/fix-fetch-items
    6.  
    Note: Please review and compare branches with original apple-unityplugins. It worked and it didn't contain anything other than fixes at the time of posting but any of the branches may get updated in the future so be safe and verify what you're merging.

    Then the only extra thing I did was to change GKIdentityVerificationResponse.cs constructor at line 30 from internal to public. Ensure that you have Unity 2020.3.33f1 on your mac and compile with python3 build.py.

    Idk if it solves all issues but it did work for us and we got GameCenter login working and the solution is usable on Windows machines, too.

    Credit to dodgy-ltd and muZZkat who made the actual fixes and to MousePods who linked it here.

    Build flow:
    Code (CSharp):
    1. xcodebuild -sdk iphoneos -configuration Release -workspace /<REDACTED>/Unity-iPhone.xcworkspace -scheme Unity-iPhone build
    2. xcodebuild -workspace /REDACTED/Unity-iPhone.xcworkspace -scheme Unity-iPhone archive -sdk iphoneos -configuration Release -archivePath /REDACTED/Build/ios/archive/Unity-iPhone
    3. xcodebuild -exportArchive -archivePath Build/ios/archive/Unity-iPhone.xcarchive -exportOptionsPlist /path_to/exportOptions.plist -exportPath Build/ios/export
    ExportOptions.plist
    Code (CSharp):
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    3. <plist version="1.0">
    4. <dict>
    5.     <key>compileBitcode</key>
    6.     <false/>
    7.     <key>method</key>
    8.     <string>app-store</string>
    9.     <key>provisioningProfiles</key>
    10.     <dict>
    11.         <key>REDACTED</key>
    12.         <string>REDACTED</string>
    13.     </dict>
    14.     <key>signingCertificate</key>
    15.     <string>REDACTED</string>
    16.     <key>signingStyle</key>
    17.     <string>manual</string>
    18.     <key>stripSwiftSymbols</key>
    19.     <true/>
    20.     <key>teamID</key>
    21.     <string>REDACTED</string>
    22.     <key>thinning</key>
    23.     <string>&amp;lt;none&amp;gt;</string>
    24. </dict>
    25. </plist>
    26.  
    Redacted company/bundle ids but I tried to include all relevant parts from our CI pipeline. I hope it helps at least a bit but tbh we were changing so many things in the build settings in the meantime that I'm not even sure what part did the trick.
     
    Last edited: Jul 25, 2023
  9. lucillegames

    lucillegames

    Joined:
    Aug 31, 2018
    Posts:
    1
    kogi_rc likes this.
  10. Telesto26

    Telesto26

    Joined:
    Dec 31, 2020
    Posts:
    13
    @kogi_rc Your are one of the greatest developers, thanks for the details instructions. After several months of failed attempts, finally it works. Again, thank you!
     
    qball13z and kogi_rc like this.
  11. chin13577

    chin13577

    Joined:
    May 8, 2017
    Posts:
    17
    @kogi_rc You are a life saver. it works like a charm. Thank you!
     
    kogi_rc likes this.
  12. davemeta

    davemeta

    Joined:
    Jul 17, 2012
    Posts:
    17
    How is this still not fixed for major release versions 4 months later?

    Seems like a perpetual issue that upgrading anything is worse than sticking to years-old versions.

    Thanks to community members for being the ones to fix it while companies with billions of dollars don't give a single f*ck.
     
  13. camillazi

    camillazi

    Joined:
    Sep 28, 2020
    Posts:
    6
    Hi, thank you for the detailed response. I'm experiencing a similar issue where the app crashes on startup with GameKitWrapper. I fetched and merged the branch muzzkat/muzzkat/fix-fetch-items, built python3 build.py with Unity 2020.3.33f1, and also updated the GKIdentityVerificationResponse.cs but I'm still getting this error. I'm a newbie to iOS development and xcode, hope someone can help. :(

    Code (CSharp):
    1. [558:64019] [DYMTLInitPlatform] platform initialization successful
    2. [558:63833] Error loading /var/containers/Bundle/Application/<><>/Frameworks/UnityFramework.framework/UnityFramework:  dlopen(/var/containers/Bundle/Application/<>/<>/Frameworks/UnityFramework.framework/UnityFramework, 265): Library not loaded: @rpath/GameKitWrapper.framework/GameKitWrapper
    3.   Referenced from: /var/containers/Bundle/Application/<>/<>.app/Frameworks/UnityFramework.framework/UnityFramework
    4.   Reason: no suitable image found.  Did find:
    5.     /private/var/containers/Bundle/Application/<>/<>.app/Frameworks/GameKitWrapper.framework/GameKitWrapper: missing LC_DYLD_INFO load command
    6.     /private/var/containers/Bundle/Application/<>/<>.app/Frameworks/GameKitWrapper.framework/GameKitWrapper: missing LC_DYLD_INFO load command
     
  14. ycode

    ycode

    Joined:
    May 1, 2016
    Posts:
    4
    @camillazi I wondered that the Unity editor version of your Unity project might be different from 2020.3.33f1.

    If that is the case, you should either switch the editor version of your unity project to 2020.3.33f1 via Unity Hub, or switch the editor version of the Unity projects of the apple-unity plugins.

    If you go with the latter one, then you need a few extra steps in the plugin build steps.
    1. apply the patches from the awesome contributors to your local repo of `apple/apple-unityplugins` as @kogi_rc described above.
    2. switch Unity editor version of the Unity project of each plugin source. For example, in the case of `Apple.Core`:
      1. add the existing Unity project at `plug-ins/Apple.Core/Apple.Core_Unity` on Unity Hub
      2. switch Unity editor version of `Apple.Core_Unity` project to the same version as your Unity project use
      3. after the editor version switch complete and a Unity editor open, just close the editor
    3. after repeating the steps above for the plugins you need, run `python3 ./build.py`
      • just in case, check the build outputs to see whether the plugins are built with the same Unity version as your Unity project
    4. add the plugins from the built tarball files to your Unity project via the package manager
    With my project using `Apple.Core` and `Apple.Apple.GameKit`, I confirmed it made the plugin work with Unity editor 2021.3.31f1 and 2022.3.11f1. My Xcode version is 15.0.1 in both case.
     
    DacDoudou and camillazi like this.
  15. lamyaslamyas

    lamyaslamyas

    Joined:
    Jan 6, 2023
    Posts:
    2
    @kogi_rc Your solution not only resolved my issue but also significantly saved me a substantial amount of time. Thank you indeed.
     
  16. squigglebucket

    squigglebucket

    Joined:
    Feb 19, 2016
    Posts:
    14
    @kogi_rc and @ycode thank you so much for your help with this. I never could've figured out how to get past this on my own lol.

    @ycode @camillazi - I got it working in 2022.3.11.f1 with your steps above, but I also had to go into Edit > project settings > Apple Build Settings and change the minimum ios version to 14.0.

    thanks to this comment for the 14.0 fix: https://forum.unity.com/threads/gklocalplayer-local-fetchitems-error-on-unity.1395694/#post-8928227

    I haven't actually built with any of my code that uses the plugins atm, but these threads at least got my app up and running with the packages in it. I really hope Apple gets the issue fixed officially soon.
     
    camillazi likes this.
  17. squigglebucket

    squigglebucket

    Joined:
    Feb 19, 2016
    Posts:
    14
    I've got a build working that can authenticate using the GKLocalPlayer.Authenticate(), so the changes made in my comment above definitely work. I also am able to use GKAccessPoint functions without issue.

    But I can't get all of the Game Kit features to work.

    For instance, if I try to use the GKGameCenterViewController as shown in the plugin's documentation:

    var gameCenter = GKGameCenterViewController.Init(GKGameCenterViewController.GKGameCenterViewControllerState.Achievement);


    it throws a C# exception about there not being a default constructor for the class.

    More importantly though, I can't seem to get GKAchievement.LoadAchievements() or GKAchievementDescription.LoadAchievementDescriptions() to work. Both of these functions cause the app to throw an exception at the xcode level (sorry if this is the incorrect way to describe it; I'm new to ios/xcode dev):

    libc++abi: terminating due to uncaught exception of type Il2CppExceptionWrapper xcode


    I have achievements configured in the dev portal for the app, and I am able to see them if I click on the GKAccessPoint and go to the app's achievement list in the Game Center window.

    I did delete a couple of them from the portal after testing and the removals weren't reflected in the access point's achievement list, so I'm not sure if the error I'm seeing is something wrong with the plugin, or if it's something wrong with my app setup/connection.

    Anyone have any experience with this?
     
  18. An-mo

    An-mo

    Joined:
    Aug 28, 2017
    Posts:
    4
    I was experiencing the same error when trying to load achievements and post achievement progress to GameKit. I created a link.xml file in the /Assets/ folder which fixed my issue.

    Code (CSharp):
    1. <linker>
    2.   <assembly fullname="Apple.Core" ignoreIfMissing="1" preserve="all"/>
    3.   <assembly fullname="Apple.GameKit" ignoreIfMissing="1" preserve="all"/>
    4. </linker>
    Hope this helps someone else.

    Andy
     
  19. squigglebucket

    squigglebucket

    Joined:
    Feb 19, 2016
    Posts:
    14
    @An-mo you are a life saver thank you! That worked basically perfectly.

    I got a different X Code error after adding the link.xml file:

    Assertion failed: (false && "compact unwind compressed function offset doesn't fit in 24 bits"), function operator(), file Layout.cpp, line 5758.


    but was able to resolve it with the help of this thread: https://forum.unity.com/threads/project-wont-build-using-xode15-release-candidate.1491761/

    I had to add "-Id_classic" to the list in UnityFramework > Build Settings > Other Linker Flags
     
    leroks and An-mo like this.
  20. camillazi

    camillazi

    Joined:
    Sep 28, 2020
    Posts:
    6
    Thank you so much! I followed these steps plus @squigglebucket advice to update to minimum iOS version 14.0.

    Build from Xcode is no longer crashing on startup. Thanks!
     
  21. liuyongjiefotoable

    liuyongjiefotoable

    Joined:
    Oct 22, 2021
    Posts:
    2
  22. Voodoocado

    Voodoocado

    Joined:
    Aug 19, 2018
    Posts:
    11
    When running the build script from the latest Apple source or kogi_rc solution, I get this error

    Code (CSharp):
    1. xcodebuild: error: The project named "AppleCoreNative" does not contain a scheme named "iOS - Release". The "-list" option can be used to find the names of the schemes in the project.
    Running the -list option gives me

    Code (CSharp):
    1.  
    2.     Schemes:
    3.         All
    4.         GameKitWrapper iOS
    5.         GameKitWrapper tvOS
    6.         GameKitWrapperMac
    7.  
    I've been able to get past this, by editing the upi_build_context.py from

    command = ["xcodebuild", "-scheme", f"{platform} - {self.build_config}", "-destination", f"{destination}", "clean", "build"]


    to

    command = ["xcodebuild", "-destination", f"{destination}", "clean", "build"]


    and running it with

    python3 build.py --plugin-list Core GameKit --platforms iOS


    Not sure if this is the correct way.

    Still stuck with the missing GameKitWrapper error.

    Really wish there could be a solid solution to all this.
     
    Last edited: Jan 14, 2024
  23. DacDoudou

    DacDoudou

    Joined:
    May 24, 2019
    Posts:
    7
    Hey @Voodoocado,

    About the command line: I used that one with the kogi_rc solution:

    python3 build.py -p Core GameKit -m iOS macOS

    About the GameKitWrapper error: try to set both GameKitWrapper and AppleCoreNative frameworks to "Embed and Sign" in the framework list in xcode (click on Unity-iPhone project then on the right go to TARGETS > UnityFramework > General)
    Also remember to also add your Team in UnityFramework > Signing & Capabilities so there is a Certificate

    You'll also need to active a fake (or real if you want) leaderboard in Apple Connect > Services > Gamecenter to have Game Center linked to your project.

    Hope this helps
     
    Voodoocado likes this.
  24. DacDoudou

    DacDoudou

    Joined:
    May 24, 2019
    Posts:
    7
    Nevermind

    Having them to "embed and sign" does work when building on a device but is not allowed when uploading to App Store Connect. Have to find another solution.
     
  25. Voodoocado

    Voodoocado

    Joined:
    Aug 19, 2018
    Posts:
    11
    Yes, I also ran into the issue with Embed and Sign causing the archive to fail.
    Haven't found a solution yet. I wonder how it is for the other people who have succeeded with this.
     
  26. DacDoudou

    DacDoudou

    Joined:
    May 24, 2019
    Posts:
    7
    I managed to do it:
    You put it as not embed in UnityFrameworks
    But you also manually add these 2 frameworks (core and gamekitwrapper) to the Unity-Iphone frameworks too but as embed that time.

    It worked like a charm and passed in production, even if these two are duplicated

    Hope this helps

    Note: even manage to add Cloudkit bindings from one of the PR in the apple repository using that workaround
     
  27. Voodoocado

    Voodoocado

    Joined:
    Aug 19, 2018
    Posts:
    11
    YES! That works.

    It makes sense, because xcode wants us to not have nested frameworks.
    This method puts all frameworks on the same level.

    After that, I ran into a issue "Could not load services for GameKit. This likely means your game is missing the com.apple.developer.game-center entitlment." when trying to run GKLocalPlayer.Authenticate.

    That was solved by
    • In the developer portal
      • Identifiers -> Add the compatibility Game Center
      • Profiles -> Update the profile with the new identifier
    • In xcode
      • Unity-iPhone -> Signing and Compatibility -> Download the updated profile
      • Click +Capability -> Game Center