Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Unity 2019 + Xcode 14: Bitcode errors when building

Discussion in 'iOS and tvOS' started by waldgeist, Sep 22, 2022.

  1. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    386
    I tried to build my existing Unity 2019.4.40 app with Xcode 14, but ran into build errors due to missing Bitcode. After searching on Apple's forums, I found out that this can be resolved by enabling Bitcode for all build targets under the Pods project, but it is pretty annoying to do this manually after any build. Can this be automated somehow?
     
    tthibault likes this.
  2. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    386
  3. tthibault

    tthibault

    Joined:
    Oct 5, 2021
    Posts:
    4
    I'm having the same issue on Unity 2020.3.39 with a project that was working before I upgraded to Xcode 14. I get the Bitcode build error for one of the 3rd party Pods I'm using
     
  4. tthibault

    tthibault

    Joined:
    Oct 5, 2021
    Posts:
    4
    I added the following to my podfile until this can be resolved. I only needed it for one target. You could remove the if check if you need it for more than a named target.

    post_install do |installer|
    installer.pods_project.targets.each do |target|
    if target.name == "MSAL"
    puts "Processing for enable bit code"
    target.build_configurations.each do |config|
    config.build_settings['ENABLE_BITCODE'] = 'YES'
    end
    end
    end
    end

     
    waldgeist likes this.
  5. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    386
    How do you modify the podfile from within Unity?
     
  6. tthibault

    tthibault

    Joined:
    Oct 5, 2021
    Posts:
    4
    waldgeist likes this.
  7. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    386
    Thanks for the clarification!
     
  8. KyleFormella

    KyleFormella

    Joined:
    Jul 19, 2018
    Posts:
    7
    @waldgeist Thanks for opening this thread. I attempted to update to latest 2020 LTS hoping Unity introduced a fix, but alas no.

    I had a separate question; are you also finding that the Xcode project created by Unity no longer retains the "Display Name", "Version", and "Build" anymore? I only recently updated to Xcode 14.
     
  9. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    386
    Oh. Just checked this with Unity 2019.4, and yes: these infos are indeed missing. Any more "surprises"?
     
  10. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    386
    Damn. I knew I should never update to the latest macOS. Now I am forced to use Xcode 14 or downgrade my Mac again.
     
    ilievant likes this.
  11. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    386
    Still missing any info why Xcode is all of the sudden requiring Bitcode?
     
  12. IgorBoyko

    IgorBoyko

    Joined:
    Sep 28, 2020
    Posts:
    90
  13. IgorBoyko

    IgorBoyko

    Joined:
    Sep 28, 2020
    Posts:
    90
    Fixed all my builds by doing this:
    Code (CSharp):
    1.  
    2.     [PostProcessBuild(999)]
    3.     public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    4.     {
    5.         if (buildTarget != BuildTarget.iOS)
    6.         {
    7.             return;
    8.         }
    9.  
    10.         var projPath = PBXProject.GetPBXProjectPath(path);
    11.  
    12.         var project = new PBXProject();
    13.         project.ReadFromFile(projPath);
    14.  
    15.         var mainTargetGuid = project.GetUnityMainTargetGuid();
    16.  
    17.         foreach (var targetGuid in new[] {mainTargetGuid, project.GetUnityFrameworkTargetGuid()})
    18.         {
    19.             project.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
    20.         }
    21.  
    22.         project.WriteToFile(projPath);
    23.     }
     
    gilzoide and gamefish like this.
  14. gamefish

    gamefish

    Joined:
    Jul 5, 2013
    Posts:
    14
    Confirm this resolved my problem, since there is no “Enable Bitcode” in building settings in xcode 14, this process will add that option there for every target
     
  15. Paracetamlol

    Paracetamlol

    Joined:
    Sep 25, 2019
    Posts:
    3
    Where to add that code?

    Guys please give few more details, not everyone is an experience developer
     
  16. IgorBoyko

    IgorBoyko

    Joined:
    Sep 28, 2020
    Posts:
    90
    Simply add this as .cs script anywhere in Assets folder
     
  17. BurntShooter

    BurntShooter

    Joined:
    Jan 1, 2016
    Posts:
    6
    Sorry to rev thread, but I'm getting an error when trying to compile this as a script:



    error CS0106: The modifier 'public' is not valid for this item



    Any idea how to go about fixing this?
     
    Last edited: Dec 4, 2022
  18. IgorBoyko

    IgorBoyko

    Joined:
    Sep 28, 2020
    Posts:
    90
    This method has to be put in a class. The example provided does not define any class.
     
  19. BurntShooter

    BurntShooter

    Joined:
    Jan 1, 2016
    Posts:
    6
    Ah, thanks a lot, that did it!

    I'm getting new errors, saying that the type or namespace for 'BuildTarget', 'PostProcessBuildAttribute', and 'PostProcessBuild' could not be found. Do i need to define these variables in the script, or import a specific namespace?

    Apologies if I'm missing something very obvious, I am very new to programming in Unity.
     
  20. PFUnity3

    PFUnity3

    Joined:
    Sep 2, 2021
    Posts:
    1
    Correct, this error usually shows up when you need to import a namespace. in this case it looks like you need at least "using UnityEditor" and "using UnityEditor.Callbacks" at the top of the file
    If you're using the included Visual Studio, you can get hints on the needed namespace by right clicking the error in VS and looking at "quick actions and refactoring" in the context menu
    Otherwise you can check the documentation, most example code will have the necessary includes
     
  21. BurntShooter

    BurntShooter

    Joined:
    Jan 1, 2016
    Posts:
    6

    Yup, I had to import UnityEditor.Callbacks and UnityEditor.iOS.Xcode for the code to work, and no more errors started showing up in the console... Until i try to export the build, at which point it fails, and i get thrown a bunch of the same errors in the script, saying various types and namespaces could not be found.

    This really threw me off, as I'm now longer sure where the error could be. I'm assuming this means that there's something wrong with the way I've written this script, but I'm not sure where the fault lies.

    Here's what my script looks like for reference:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5. using UnityEditor.Callbacks;
    6. using UnityEditor.iOS.Xcode;
    7.  
    8. public class iosbuild : MonoBehaviour
    9. {
    10.  
    11.     [PostProcessBuild(999)]
    12.     public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    13.     {
    14.  
    15.         if (buildTarget != BuildTarget.iOS)
    16.         {
    17.             return;
    18.         }
    19.         var projPath = PBXProject.GetPBXProjectPath(path);
    20.         var project = new PBXProject();
    21.         project.ReadFromFile(projPath);
    22.         var mainTargetGuid = project.GetUnityMainTargetGuid();
    23.         foreach (var targetGuid in new[] {mainTargetGuid, project.GetUnityFrameworkTargetGuid()})
    24.         {
    25.             project.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
    26.         }
    27.         project.WriteToFile(projPath);
    28.     }
    29.  
    30. }
    31.  
    EDIT: Turns out, as I'm using UnityEditor, which makes the script an Editor Extension; The code is not available at run time. The solution was to just drop the script in the Assets > Editor Folder, and it compiles just fine!
     
    Last edited: Dec 6, 2022
    SirhotBay, Tinsa and PFUnity3 like this.
  22. samanabo

    samanabo

    Joined:
    Mar 10, 2015
    Posts:
    51
    Thanks for this post. Helped me out with Unity 2022.2.0f1 as well