Swift "Invalid Mach-O Format" Error [duplicate] - ios

I just got this error when submitting an app to the app store.
Does this mean I need to set ENABLE_BITCODE for all dependencies? I tried that but then got errors saying the dependencies were not compatible with bitcode (or something like that)...

I had the same problem earlier this morning. In fact the answer is in the error : "Verify that all of the targets for a platform have a consistent value for the ENABLE_BITCODE build settings"
I had a target (with ENABLE_BITCODE set to NO), using multiple pods having ENABLE_BITCODE set to YES. So, all I had to, do is set ENABLE_BITCODE to YES in my project target. But I guess you have a choice, you can also set ENABLE_BITCODE to NO in all the libs your are using.

The easiest and most common fix:
You can uncheck "Include Bitcode" when submitting the app via Xcode.
If you use xcodebuild, you can use pass an exportOptionsPlist with the value of uploadBitcode set to false. In my case, we're using xctool to build the app and don't have the ability to pass an exportOptionsPlist, so we had to remove bitcode from all of our frameworks.
If anyone is using cocoapods and wants to disable bitcode for their frameworks, you can just add the following to your podfile:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
Via https://stackoverflow.com/a/32685434/1417922
To add a little more clarification as to what's going on with this issue:
It seems that apple just started enforcing this yesterday. If your main binary has bitcode disabled, but you include a static library or framework that has bitcode enabled, it will fail validation. It goes the other way too: if your main binary has bitcode enabled, but you include a library/framework that has bitcode disabled, it will fail validation.
I had a few dependencies from GoogleMaps and Amazon that made it non trivial to switch everything to enable bitcode, so I simply disabled it and removed bitcode from one static library I had imported in my project. You can strip bitcode from any binary by using this following command
$ xcrun bitcode_strip -r {Framework}.dylib -o tmp.dylib
$ mv tmp.dylib {Framework}.dylib
https://developer.apple.com/library/content/documentation/Xcode/Conceptual/RN-Xcode-Archive/Chapters/xc7_release_notes.html
While the above are solutions to the problem, I don't agree that if the main binary has bitcode disabled that all of the included binaries should need it as well. Bitcode is just some IR code that Apple can use for app thinning--why don't they just strip it from other binaries (which I assume is what they previously did)? This doesn't make a ton of sense to me.
Apple thread https://forums.developer.apple.com/thread/48071

I just unchecked "include bitcode" and it started to upload

For Carthage
Open your libraries in your project folder (Carthage->Checkouts->[lib name])
Then open each lib in Xcode
Set Enable Bitcode - No in build settings
Do it for each lib in your list
Build carthage carthage build --platform xxx
Then you can archive and submit to the Appstore successfully

We were getting same error "Xcode - Error ITMS-90635 - Invalid Mach-O in bundle - submitting to App store" from last friday (3-june-2016) .. used the below mentioned 2 steps to get this done
Step 1:
Added code to pod file to mark 'ENABLE_BITCODE' = 'NO' in pods
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
Step 2:
Marked 'ENABLE_BITCODE' = 'NO' in pods for the project
Note: Tried with marking 'ENABLE_BITCODE' = 'YES' in pods and in my project too but as we are using twillio framework for calling which has a flag -read_only_relocs which does not allow compilation with 'ENABLE_BITCODE' = 'YES'. So if your app does not use any of such framework with -read_only_relocs then you can proceed with making 'ENABLE_BITCODE' = 'YES' as it will be good for your app.

For those who are having build error after setting "Enable BitCode" to Yes.
I have to update all the library.But,the easiest part is I use Cocoapods.So,please update all your pod project : (One by one) or All
Then set Enable BitCode to "No" before you archive.
Then Archive>>Upload>>It will pass this error.
Cheers.

I had the same issue with project "ENABLE_BITCODE = YES" and dependencies "ENABLE_BITCODE = YES" on my CI with Xcode 7.3.
Solution was updating Xcode to latest available version (7.3.1)

Related

Excluding arm64 architecture leads to 'No such module: AWSAppSync'

I am currently working on a Swift 5.0 project (Xcode 12). I currently use an M! computer. For my project, I have a couple of pod dependencies that I need (AWS, Google, etc) to make my project work. When I run my code on a IOS device, I encounter no issues. But when I try to run the project on a simulator, I run into different errors involving the pod linking.
The Google places autocomplete FAQ says that if I have troubles building on an iOS simulator using Xcode 12, I should exclude the arm64 architecture for iOS simulators by altering the project build settings. But upon doing that, I get a warning of "No such module found: AWSAppSync".
In attempting to fix this, I've added 'x86_64' and 'x86' to architectures, set "Build Active Architecture Only" to "yes", and made sure my pod's build settings have the same "Build Active Architecture Only" value, which results in no change. I have also tried pod update, install, install --repo-update, cleaning the build folder, deleting derived data, and restarting Xcode.
When I set "Build Active Architecture Only" to "No" for both sets of build settings (pod and project), I get another error from a different non-AWS pod:
"Could not find module 'MultiSlider' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios-simulator"
Removing any code references to the multi slider then lets the app fully build, but the app crashes before launching on the simulator with an error of "unrecognized selector sent to instance 0x60000067fd90".
Note that with any of these attempted fixes, the app continues to run on an actual iOS device as expected. I'm very new to pods and would really appreciate any help or insight anyone could offer! Thank you in advance.
I had to exclude the arm64 architecture for each of the pods when building for the simulator. See https://narlei.com/development/apple-m1-xcode-error-when-build-in-simulator/ for more details, but it seems that excluding arm64 from the project AND excluding it in the Podfile for each pod's target is necessary.
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
config.build_settings['ONLY_ACTIVE_ARCH'] = 'YES'
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
end

iOS Framework on device bitcode not included

I am developing static library for iOS, in which I am using Alamofire. When I try to build for release for simulator, everything is ok, however when I try to build it for device (release or debug) I get following problem:
ld: bitcode bundle could not be generated because '/PathToMyLibraryProducts/Release-iphoneos/Alamofire/Alamofire.framework/Alamofire' was built without full bitcode. All frameworks and dylibs for bitcode must be generated from Xcode Archive or Install build for architecture armv7
My framework has enabled bitcode, and it is fat framework (build for device and simulator). How can I resolve that?
If you are using cocoapods-binary with cocoapods
This error will appear since cocoapods-binary won't generate frameworks with bitcode enabled unless you specifically indicate that by using this key in your Podfile:
enable_bitcode_for_prebuilt_frameworks
This is how your Podfile will look:
plugin 'cocoapods-binary'
platform :ios, '12.0'
use_frameworks!
enable_bitcode_for_prebuilt_frameworks!
all_binary!
target 'ProjectName' do
pod 'Alamofire'
end
Found this discussion which may be relevant
In summary the following setting is needed:
BITCODE_GENERATION_MODE=bitcode for Release builds and BITCODE_GENERATION_MODE=marker for Debug builds
Hope that helps.
Kind regards,
Mukund
I think, bitcode is not enabled while you are building for Generic Device. So do the following:
Under pods.xcodeproj, select all pods target.
Navigate under Build Settings and make sure that all your
"Pods" > "Build Settings" > "Build Active Architecture Only" is set
to "NO".
Enable Bitcode set to YES
Then, tap on project target, and follow the Step 2 and 3
Clean the build and make Archive
Add this code in your pod file, It will enable Bitcode for all the framework.
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'YES'
end
end
end

ITMS-90668 - Invalid Bundle Executable. The executable file contains incomplete bitcode

Yesterday I started to get strange error message from iTunes Connect:
ITMS-90668
Invalid Bundle Executable.
The executable file '...' contains incomplete bitcode.
To compile binaries with complete bitcode, open Xcode and choose Archive in the Product menu.
Actually, I am getting many identical messages for each of my embedded frameworks.
I do use Bitcode, and I have not changed anything related Bitcode in my project.
It seems like a new ITMS requirement (or bug). And I have no idea how to fix it.
Looks like this problem mysteriously related to CI tools like Shenzhen or BuddyBuild. Or, maybe, it is related to cases when dependencies contain precompiled code.
Just in case, my app:
Has these dependencies which have precompiled code:
BuddyBuildSDK, Firebase, CardIO.
Written in Swift.
Has iOS Keyboard Extension.
Use BuddyBuild.
Use CocoaPods.
Update:
I had changed virtually nothing and then the problem did disappear yesterday. I have no idea why exactly. I believe Apple just fixed that bug or it is fluke problem.
I had the same problem with some pod dependencies. I changed "Enable Bitcode" build setting for each pod projects causing the issue (following the error descriptions from itunesconnect). Now everything works.
You can set it in the Podfile. Here an example that changes for each dependencies:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
Found here: Disable bitcode for project and cocoapods dependencies with Xcode7?
Just register a problem in the git card.io library:
https://github.com/card-io/card.io-iOS-SDK/issues/205
I hope to resolve this situation as soon as possible!

Xcode - Error ITMS-90635 - Invalid Mach-O in bundle - submitting to App store

I just got this error when submitting an app to the app store.
Does this mean I need to set ENABLE_BITCODE for all dependencies? I tried that but then got errors saying the dependencies were not compatible with bitcode (or something like that)...
I had the same problem earlier this morning. In fact the answer is in the error : "Verify that all of the targets for a platform have a consistent value for the ENABLE_BITCODE build settings"
I had a target (with ENABLE_BITCODE set to NO), using multiple pods having ENABLE_BITCODE set to YES. So, all I had to, do is set ENABLE_BITCODE to YES in my project target. But I guess you have a choice, you can also set ENABLE_BITCODE to NO in all the libs your are using.
The easiest and most common fix:
You can uncheck "Include Bitcode" when submitting the app via Xcode.
If you use xcodebuild, you can use pass an exportOptionsPlist with the value of uploadBitcode set to false. In my case, we're using xctool to build the app and don't have the ability to pass an exportOptionsPlist, so we had to remove bitcode from all of our frameworks.
If anyone is using cocoapods and wants to disable bitcode for their frameworks, you can just add the following to your podfile:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
Via https://stackoverflow.com/a/32685434/1417922
To add a little more clarification as to what's going on with this issue:
It seems that apple just started enforcing this yesterday. If your main binary has bitcode disabled, but you include a static library or framework that has bitcode enabled, it will fail validation. It goes the other way too: if your main binary has bitcode enabled, but you include a library/framework that has bitcode disabled, it will fail validation.
I had a few dependencies from GoogleMaps and Amazon that made it non trivial to switch everything to enable bitcode, so I simply disabled it and removed bitcode from one static library I had imported in my project. You can strip bitcode from any binary by using this following command
$ xcrun bitcode_strip -r {Framework}.dylib -o tmp.dylib
$ mv tmp.dylib {Framework}.dylib
https://developer.apple.com/library/content/documentation/Xcode/Conceptual/RN-Xcode-Archive/Chapters/xc7_release_notes.html
While the above are solutions to the problem, I don't agree that if the main binary has bitcode disabled that all of the included binaries should need it as well. Bitcode is just some IR code that Apple can use for app thinning--why don't they just strip it from other binaries (which I assume is what they previously did)? This doesn't make a ton of sense to me.
Apple thread https://forums.developer.apple.com/thread/48071
I just unchecked "include bitcode" and it started to upload
For Carthage
Open your libraries in your project folder (Carthage->Checkouts->[lib name])
Then open each lib in Xcode
Set Enable Bitcode - No in build settings
Do it for each lib in your list
Build carthage carthage build --platform xxx
Then you can archive and submit to the Appstore successfully
We were getting same error "Xcode - Error ITMS-90635 - Invalid Mach-O in bundle - submitting to App store" from last friday (3-june-2016) .. used the below mentioned 2 steps to get this done
Step 1:
Added code to pod file to mark 'ENABLE_BITCODE' = 'NO' in pods
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
Step 2:
Marked 'ENABLE_BITCODE' = 'NO' in pods for the project
Note: Tried with marking 'ENABLE_BITCODE' = 'YES' in pods and in my project too but as we are using twillio framework for calling which has a flag -read_only_relocs which does not allow compilation with 'ENABLE_BITCODE' = 'YES'. So if your app does not use any of such framework with -read_only_relocs then you can proceed with making 'ENABLE_BITCODE' = 'YES' as it will be good for your app.
For those who are having build error after setting "Enable BitCode" to Yes.
I have to update all the library.But,the easiest part is I use Cocoapods.So,please update all your pod project : (One by one) or All
Then set Enable BitCode to "No" before you archive.
Then Archive>>Upload>>It will pass this error.
Cheers.
I had the same issue with project "ENABLE_BITCODE = YES" and dependencies "ENABLE_BITCODE = YES" on my CI with Xcode 7.3.
Solution was updating Xcode to latest available version (7.3.1)

Unable to archive build with Share Extension and AFNetworking Cocoapod

I've got a share extension set up for my app and I'm using AFNetworking through a cocoapods install.
I was able to build and run the app through simulator and my phone via debug builds but when I tried to archive to submit to the app store I ran into a warning:
linking against dylib not safe for use in application extensions
AFNetworking
Archive builds would complete but they would be corrupted and unusable.
My solution is to stop using cocoapods for my app extension and manually add the AFNetworking files to my Compile Resources build setting.
I'm just wondering if others have had this issue OR if they have had no problems using AFNetworking cocoapod to submit an extension to the store.
I have checked out the Apple Guidelines and was using arm64 architecture and had set the target’s “Require Only App-Extension-Safe API” build setting to Yes.
As far as i know the latest version of cocoapods should set automatically "Allow app extension API only" flags to all libs targets if pods library is properly linked to extension target(s) (check targets from Pods.xcodeproj). If it doesn't happen you can try to set it manually in post_install hook. You can try this one:
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'YES'
end
end
end

Resources