Declare Architecture in Podfile - ios

Is there a way to include the architecture in a CocoaPods Podfile? I am trying to build my app for both 32 and 64 bit but when I switch to Standard architectures (including 64-bit) in my project's build settings, it complains that I should let it automatically choose architectures. Doing this reverts my project back to Standard architectures. I have a feeling that Xcode is doing this because the Pods project (in my Xcworkspace) does not include 64-bit in its architectures. Is there a way to add this to the Podfile(I assume better if Pod does it itself) or should I change it in the Pods project as well.
My current Podfile:
xcodeproj 'Nobles/Nobles.xcodeproj'
platform :ios, '7.0'
pod 'Reachability'
pod 'TWTSideMenuViewController'

I'm searching for answers to a similar issue and found this:
Resolving CocoaPods build error due to targets building for only active architecture
I always have a build error after pod install, because by default, CocoaPods will configure your pods to build for active architecture only (during debugging).
The solution is to change Pods project setting Build Active Architecture Only to NO for debug.
But it is tedious to change every time after you run pod install (as your change will get reverted back to YES).
As suggested by msmollin in CocoaPods issues, you can fix by with:
# Append to your Podfile
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
end
end
end
Maybe this can help you?

CocoaPods can't do what you want. It can give you different versions of the library, but it doesn't know anything about how that library was built.
Run xcrun -sdk iphoneos lipo -info libYourLibraryName.a to see which architectures it was built for.
If this is an open-source library, you can build it yourself, instead of just linking the .a file. If you don't have access to the library source, and the .a file doesn't include the 64 bit slice, I'm afraid you're out of luck. Contact the developer and ask them to build the library with the 64 bit support.

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

Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture x86_64

There is Xcode error info:
in FFmpeg/Classes/lib/libavcodec.a(aacencdsp.o), building for iOS
Simulator, but linking in object file built for free standing, file
'FFmpeg/Classes/lib/libavcodec.a' for architecture x86_64.
My library file libavcodec.a supports x86_64, i386, arm64, armv7 arm7 and so on.
I have set below code in Podfile, then pod install but didn't work.
config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
config.build_settings['VALID_ARCHS[sdk=iphonesimulator*]'] = 'x86_64'
I had the same issue, i tried this for Xcode version 12
Change your react-native-ffmpeg version to version 0.4.4 in your package.json
ie "react-native-ffmpeg": "0.4.4"
Update the library
"npm install" from your project root directory
Cleaning react-native-ffmpeg pod caches
cd ios
pod cache clean react-native-ffmpeg --all
Update your pod file in [ios] folder.
replace the line containing react-native-ffmpeg with the below
pod 'react-native-ffmpeg/https-lts', :path => '../node_modules/react-native-ffmpeg'
Installing Pod
cd ios
pod install
Cleaning your app build folder.
Open your project in Xcode and press (⇧⌘K) to clean your build before.
OR -> in Xcode go to (Product => Clean build folder).
✅ Now run your app from Xcode.
Reference: https://github.com/tanersener/react-native-ffmpeg/issues/196#issuecomment-700935317
Salehjarad comment
I think you will find your answer here https://stackoverflow.com/a/63955114/2864316
Basically you need to exclude the arm64 architecture from simulator builds. You can do this manually, or change your pod file as detailed in the linked answer.
At least that answer fixed my issue 👍
I had the same issue. I use react-native, but react-native-ffmpeg depend on mobile-ffmpeg. Solution for me was to use the LTS version of package.
Put this at the end of the Podfile:
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings[‘EXCLUDED_ARCHS[sdk=iphonesimulator*]’] = ‘arm64’
config.build_settings['VALID_ARCHS[sdk=iphonesimulator*]'] = 'x86_64'
end
end
Basically you may have to do:
Main project target
Pod project target

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

React Native XCode Project Product Archive Fails with duplicate symbols for architecture arm64

Strangely, I can't seem to get Archive to work in XCode but the build succeeds without the errors on duplicate symbols if I do not attempt to Archive but simply build a release version. The project builds properly on devices as well.
I have searched up on this topic and tried disabling testability, and setting the 'No Common Blocks' in the project settings to NO as well but no luck so far.
The Project is a React Native 0.40 based project with CocoaPods installed as well. PodFile is this
# You Podfile should look similar to this file. React Native currently does not support use_frameworks!
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
# Change 'AirMapsExplorer' to match the target in your Xcode project.
target 'StreetSmart' do
pod 'React', path: '../node_modules/react-native', :subspecs => [
'Core',
'RCTActionSheet',
'RCTAnimation',
'RCTGeolocation',
'RCTImage',
'RCTLinkingIOS',
'RCTNetwork',
'RCTSettings',
'RCTText',
'RCTVibration',
'RCTWebSocket'
]
pod 'GoogleMaps' # <~~ remove this line if you do not want to support GoogleMaps on iOS
# when not using frameworks we can do this instead of including the source files in our project (1/4):
# pod 'react-native-maps', path: '../../'
# pod 'react-native-google-maps', path: '../../' # <~~ if you need GoogleMaps support on iOS
end
XCode Version is 8.2.1, and the project file is opened via .xcworkspace since pods are installed.
Would really appreciate any help or insight on this, been stuck at this for hours.
So I did even more research into this and the workaround is actually much simpler. Or at least it was in my case. The problem is that when you declare React in the podfile, the Pods xcodeproject gets a React target as part of the pod install process. Having this target in the Pods project is what causes the error when you Archive. So the fix is to remove the target.
The problem with removing the target in xCode is that this actually edits project.pbxproj file within the Pods folder which is not in version control. So while the build will archive once you do this, if you deploy from anywhere other than the machine that manually removed it, it will still fail. So the solution is to add this post install command to the bottom of your podfile:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "React"
target.remove_from_project
end
end
end
This simply loops through all the pods to be installed and removes the target for the React one. This way anywhere that builds the project, will also remove the target. Now when you build to Archive it will not fail.
Finally solved the problem after finding a relevant issue on another react-native project here.
The answer is that there is two copies of React Native in the Xcode project, one from CocoaPods and another as a subproject. Just remove all modules that were already declared in Podfile under the Libraries inside Xcode and the error goes away after a clean and re-try.
What's interesting about this issue is that all builds in Debug and Release works but it fails when attempting to Archive the project for distribution.
[Update 2 May 2017]
The solution I described above can cause debug-time errors when you run your code with react-native run-ios/android though it allows the project to be successfully archived.
An alternative method is to remove those duplicate modules that exist both in Libraries and Podfile from the Podfile declaration instead of the Libraries folder. And of course run the relevant pod commands, clean your project etc.
Doing this allowed my code to archive and also run without debug-time errors
I solved this issue by the following:
(ref.: https://github.com/react-community/react-native-maps/issues/718)
Open Xcode > Pods > Targets Support Files > Pods-{TARGET-NAME} find
"OTHER_LDFLAGS" and remove only -ObjC in these two files:
Pods-{TARGET-NAME}.release.xcconfig e
Pods-{TARGET-NAME}.debug.xcconfig
Go to project main target > Build
Settings > Other Linker Flags: Make sure no -ObjC is left in the
value I deleted the build/Build folder in ios and run your project again.
It works now.
Side effects from the link above: the app may become larger as there may be duplicated symbols in it.
Hope it can help you.

Cocoapods Completely Broke

To start: I'm using Cocoapods 0.37.2, XCode 6.3.1 compiling for iOS 8.3
My project worked just fine before I ran a basic "pod update" now it's completely refusing to compile. I'm quite positive this has nothing to do with the pods themselves. Specifically the error I'm getting is this:
ld: warning: directory not found for option '-F/Users/user_name/Library/Developer/Xcode/DerivedData/AppName-bjozswzeepmhacfkeimeepxzcxgb/Build/Products/Debug-iphoneos/include'
ld: library not found for -lPods-AppName-AFNetworking
Podfile is this:
# Uncomment this line to define a global platform for your project
platform :ios, "8.0"
def shared_pods
pod 'SocketRocket'
pod 'AFNetworking'
pod 'DateTools'
pod 'Spotify-iOS-SDK'
end
target "AppName" do
shared_pods
end
target "AppNameTests" do
shared_pods
end
I have cleared DerivedData (many many times), cleaned my builds, restarted XCode, restarted my machine, I have ensured my config files and linker config lists are set up correctly. I've been using Cocoapods for years and never had this much trouble.
Completely frustrated and confused... questioning sanity.
Any help?
Information from CocoaPods troubleshooting doc. Hope this helps you.
If Xcode complains when linking, e.g. Library not found for -lPods, it
doesn't detect the implicit dependencies:
Go to Product > Edit Scheme
Click on Build
Add the Pods static
library, and make sure it's at the top of the list
Clean and build again
If that doesn't work, verify that the source for the spec you
are trying to include has been pulled from GitHub. Do this by looking
in /Pods/. If it
is empty (it should not be), verify that the
~/.cocoapods/master//.podspec has the correct git hub url
in it.
If still doesn't work, check your Xcode build locations
settings. Go to Preferences -> Locations -> Derived Data -> Advanced
and set build location to "Relative to Workspace".

Resources