Symptoms:
- I am developing a game for iOS.
- I want to set ENABLE_BITCODE=NO in the Xcode project as the default setting for an Xcode project exported by Unity.
- I have several third-party libraries which still do not support Bitcode on iOS.
Cause:
Since Unity version 5.3.1p1, Bitcode support is enabled by default.
Resolution:
An easy way to disable Bitcode support is by using UnityEditor.iOS.Xcode.PBXProject helper class.
The documentation is available here: Unity - Scripting API: PBXProject
The following is an example of how you can change the ENABLE_BITCODE property:
using UnityEditor; using UnityEditor.Build; using UnityEditor.Build.Reporting; using UnityEngine; using UnityEditor.iOS.Xcode; class Test: IPostprocessBuildWithReport { public int callbackOrder { get { return 0; } } public void OnPostprocessBuild(BuildReport report) { if (report.summary.platform == BuildTarget.iOS) { string projectPath = report.summary.outputPath + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromFile(projectPath); //Disabling Bitcode on all targets //Main string target = pbxProject.GetUnityMainTargetGuid(); pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); //Unity Tests target = pbxProject.TargetGuidByName(PBXProject.GetUnityTestTargetName()); pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); //Unity Framework target = pbxProject.GetUnityFrameworkTargetGuid(); pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO"); pbxProject.WriteToFile(projectPath); }
More Information:
Please note: Unity does not recommend disabling Bitcode. However, there are cases where it is inevitable. Read more about what benefits you gain by enabling Bitcode in the article, 'Bitcode Support in iOS & tvOS.'
This article applies to Unity versions 2018.1 and higher.
Comments
12 comments
This was really useful, thanks. We were having issues with our iOS build and this has fixed it.
Doesn't work on compiling in Cloud Build:
Is there a way to configure Cloud Build to disable bitcode?
Andrey Dolgov - My guess would be that you've not put the script in an Editor folder which is why it can't find those classes.
Doesn't work in 2019.3, xcode doesn't even give you the option to disable bitcode manually.
I'm using:
Unity 2019.3.15
Xcode 11.5
iOS 13.5
I'm trying to build an app with easyAR but it always give me this:
/Frameworks/Plugins/iOS/easyar.framework/easyar(easyar-arm64-master.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target.
I tried going to the file that it points to and add ENABLE_BITCODE (tried NO and YES) to the Info.plist of the framework but no success.
Tried all of this in two projecs, one with firebase (generates xcworkspace) and another with easy ar only (generates xcodeproj), both had the same error.
Elizeu Emanuel Herichs Becker
The code shown here no longer works due to the way Unity has changed the targets in xcode in Unity 2019.3 and later.
I made this modification to the code to get it working again.
#if UNITY_IOS
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
public static class MyBuildPostprocess
{
[PostProcessBuild( 1000 )]
public static void PostProcessBuildAttribute( BuildTarget target, string pathToBuildProject )
{
if(target == BuildTarget.iOS)
{
string projectPath = PBXProject.GetPBXProjectPath(pathToBuildProject);
PBXProject pbxProject = new PBXProject();
pbxProject.ReadFromFile(projectPath);
string[] targetGuids = new string[2] { pbxProject.GetUnityMainTargetGuid(), pbxProject.GetUnityFrameworkTargetGuid() };
pbxProject.SetBuildProperty(targetGuids, "ENABLE_BITCODE", "NO");
pbxProject.WriteToFile (projectPath);
}
}
}
#endif
I'm using uinty2019.4 now and got the "bitcode error". The project only contains an empty scene and a third-party plugin. The method of disabling bitcode works well for unity 2018, but it doesn't work for the unity 2019.4 project. I already switched to the script provided by Nurullah.
Yuhan Yang did updated script I provide work for you? We migrated away from doing iOS builds after I set up the script so I have not triggered iOS builds in quite a while. However, I am happy to help you troubleshoot it, if it is not working for you.
Nurullah Morshed
Thanks! This worked for me in unity 2019.4
Greetings, I'm using the modified script from Nurullah in 2020.1.6f1. I need to disable bitcode for the AdMix plugin. Using the latest build from CloudBuild AdMix is not showing ads and I can't tell from the build log if CloudBuild honored the script and disabled bitcode. Any suggestions on how I can confirm if bitcode is disabled in that build?
Thanks!
Greg Bradburn Samuel Bjørn Mumm Jessen
I'm glad it helped :D
It looks like Unity finally updated their reference script to work with the new APIs as well, so hopefully this isn't a problem for people anymore!
The main problem with bitcode is not listed here. I have never seen libraries without bitcode support. What I see every day are libraries with incompatible bitcode versions.
Almost every big Xcode release comes with a new clang compiler with a new bitcode version that is incompatible with all the previous versions. New third party libraries with incompatible bitcode versions appear more often than I take a shower.
Yes, Apple recommends using bitcode. But there are NO practical benefits of using it.
For those using Unity Cloud Build - there is a config option where you can set a Custom Fastlane configuration. Can we disable bitcode in this way, instead of having to implement `IPostprocessBuildWithReport`?
Please sign in to leave a comment.