App crash on loading dependent libraries while making xcframework - ios

I am making a xcframework. In my framework project, I have added cocoa pods like Alamofire, Realm, and more. When I integrate my xcframework in my application, the application crashes showing following error:
dyld: Symbol not found: _$s9Alamofire10HTTPMethodO3getyA2CmFWC
Referenced from: /private/var/containers/Bundle/Application/E81F9FBA-3876-4959-B675-B89A4EC0257A/BykesPod.app/Frameworks/MYFRAMEWORK.framework/MYFRAMEWORK
Expected in: /private/var/containers/Bundle/Application/E81F9FBA-3876-4959-B675-B89A4EC0257A/DEMOAPP.app/Frameworks/Alamofire.framework/Alamofire
in /private/var/containers/Bundle/Application/E81F9FBA-3876-4959-B675-B89A4EC0257A/DEMOAPP.app/Frameworks/MYFRAMEWORK.framework/MYFRAMEWORK
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
Following is the pod file of my framework project
target 'MYFRAMEWORK' do
project './MYFRAMEWORK.xcodeproj'
pod 'Realm'
pod 'RealmSwift'
pod 'Alamofire', '~> 4.8'
pod 'MBProgressHUD','1.1.0'
pod 'SwiftyJSON'
end
I have added following dependencies in my podspec file:
s.dependency "Realm"
s.dependency "RealmSwift"
s.dependency "Alamofire","~> 4.8.2"
s.dependency "MBProgressHUD","~> 1.1.0"
s.dependency "SwiftyJSON"
Following is the pod file of my demo application:
target 'DEMOAPP' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod 'PODNAME'
end
Following are the commands from which I am making xcframeworks
xcodebuild archive -workspace MYFRAMEWORK.xcworkspace -scheme MYFRAMEWORK -sdk iphoneos -archivePath "archives/0/ios_device.xcarchive" BUILD_LIBRARY_FOR_DISTRIBUTION=YES SKIP_INSTALL=NO
xcodebuild archive -workspace MYFRAMEWORK.xcworkspace -scheme MYFRAMEWORK -sdk iphonesimulator -archivePath "archives/0/ios_simulators.xcarchive" BUILD_LIBRARY_FOR_DISTRIBUTION=YES SKIP_INSTALL=NO
xcodebuild -create-xcframework -framework archives/0/ios_device.xcarchive/Products/Library/Frameworks/MYFRAMEWORK.framework -framework archives/0/ios_simulators.xcarchive/Products/Library/Frameworks/MYFRAMEWORK.framework -output build/MYFRAMEWORK.xcframework
Note: My code xcode version is 12.4

Solution to this problem is to enable following option in Target Build setting
Open Target build settings in Xcode
search for Build Libraries for distribution
change it to "Yes".
Note: If you are distributing Project/Library/Framework and it contains/depends on Cocoapods add following script into your destination Project where framework is integrated.
This script enables Build Libraries for distribution for all installing Cocoapod dependencies.
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
end
end
end

Currently, the solution I found was to make the "Build Libraries for distribution" flag true in the Pods project of my application. See attached screenshot.

Related

Problem archiving project to create XcFramework

** I am running following command to create archive. **
`
xcodebuild archive \
-scheme ScannerV1 \
-configuration Release \
-destination 'generic/platform=iOS Simulator' \
-archivePath './build/ScannerV1.framework-iphonesimulator.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
`
This is my pod file
`
target 'ScannerV1' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for ScannerV1
pod 'IQKeyboardManagerSwift'
pod 'ProgressHUD'
pod 'GoogleMLKit/FaceDetection'
pod 'GoogleMLKit/BarcodeScanning'
pod 'GoogleMLKit/TextRecognition','2.2.0'
pod 'Alamofire'
# pod 'SwiftKeychainWrapper'
end
post_install do |pi|
pi.pods_project.targets.each do |t|
t.build_configurations.each do |config|
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
end
end
end
`
**This is the error I am getting . **
SwiftEmitModule normal x86_64 Emitting\ module\ for\ ScannerV1 (in target 'ScannerV1' from project 'ScannerV1') (1 failure)
Also as you can see I have commented SwiftKeychainWrapper pod . This is because I was getting error that SwiftKeychainWrapper is not found / No such module SwiftKeychainWrapper .
Now I got an error and that is : error: no such module 'Alamofire'
I mentioned above what I tried . I am expecting to create archive when creating xcframework

xCode Cocoapods build fails "Undefined symbols for architecture x86_64"

I want to build my Xcode project (react native & swift) for the simulator and on a real device.
The simulator worked great. Today I tried to build it for my device, I selected my device in the Xcode bar and added the scheme to release (I had to do this because I'm using react native and otherwise the bundle is not packed)
Then an error during the build occurs (in this case for the dependency RNPurchases, but this is completely random. sometimes it's Expo-Keep-Awake or Facebook)
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_RCPurchases", referenced from:
objc-class-ref in RNPurchases.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Even switching the back to Build Configuration Debug in my scheme has no effect anymore.
I already tried several things:
clear Xcode build
delete pod folder
remove pod cache
remove Xcode/DerivedData
reboot
nothing works.
This problem is pretty new to me, it already occurred twice within the last 2 months. Somehow I got the build for the simulator running again, but never for a device. I didn't have the problems like this half a year ago ...
My Setup
Xcode 12.4
MacBook Pro (Big Sur 11.2.3)
Build Settings for App-Target: Build Active Architectures Only: Debug YES, Release NO)
Build Settings for Pod-Target: Build Active Architectures Only: Debug YES, Release NO)
Podfile:
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/#react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/react-native-unimodules/cocoapods.rb' # expo uni modules
use_frameworks!
install! 'cocoapods', :deterministic_uuids => false, :warn_for_unused_master_specs_repo => false
target 'TrainUrTeam' do
platform :ios, '12.0'
# ... pods xyz
use_unimodules!
config = use_native_modules!
use_react_native!(:path => config["reactNativePath"])
end
post_install do |installer| # src: https://stackoverflow.com/a/64139830/6003494
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings["ONLY_ACTIVE_ARCH"] = "YES"
end
end
end
After 2 weeks of googling I could finally find a working solution according to this Post adding this to the Podfile:
use_frameworks! :linkage => :static
If use_frameworks! :linkage => :static is not an option for you, you may try to use:
pre_install do |installer|
installer.pod_targets.each do |pod|
if pod.name.eql?('RNPurchases')
def pod.build_type;
Pod::BuildType.static_library # pods version >= 1.9
# Pod::Target::BuildType.static_library # pods version < 1.9
end
end
end
end
I got these errors and just restarted my macbook, clean, then build and they disappeared. Magic.
Go to xcode project -> Build setting -> Architecture -> Excluded
architecture -> (arm64)set
Try to build & run

Build error with bit code enabled; ld: -bundle and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together

I have a pod project, containing an example that demonstrates the usage of the pod. The bitcode enabled setting is set to yes, both on the example and Pod targets. The following is the Podfile of the example:
use_frameworks!
platform :ios, '10.0'
target 'MyPod_Example' do
pod 'MyPod', :path => '../'
target 'MyPod_Tests' do
inherit! :search_paths
end
end
The example app runs well on the Simulator, but while trying to run it on an iPhone 6S, I get the following build error:
ld: -bundle and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together
clang: error: linker command failed with exit code 1 (use -v to see invocation).
How do I fix this?
Another project that I have that has the same pod, but downloads the pod from its repo works fine on iPhone, with bitcode enabled. The following shows the Podfile structure of the app that works:
source '<my pod spec repo>'
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
target 'MyPodTest' do
use_frameworks!
# Pods for MyPodTest
pod 'MyPod'
target 'MyPodTestTests' do
inherit! :search_paths
# Pods for testing
end
target 'MyPodTestUITests' do
inherit! :search_paths
# Pods for testing
end
end
The -bitcode_bundle flag being passed to ld is described in the error message ("Xcode setting ENABLE_BITCODE=YES"), but the -bundle flag is not, which can make this confusing and hard to debug.
If you look at the lines preceding this error, you will likely see two important ones:
WriteAuxiliaryFile /Users/YOURUSER/Library/Developer/Xcode/DerivedData/YOURPROJECT-xxxxx/Build/Intermediates.noindex/YOURPROJECT.build/Release-SDK/TARGET.build/DerivedSources/TARGET_vers.c (in target 'TARGET' from project 'YOURPROJECT')
CompileC /Users/YOURUSER/Library/Developer/Xcode/DerivedData/YOURPROJECT-xxxxx/Build/Intermediates.noindex/YOURPROJECT.build/Release-SD/TARGET.build/Objects-normal/arm64/TARGET_vers.o /Users/YOURUSER/Library/Developer/Xcode/DerivedData/YOURPROJECT-xxxxx/Build/Intermediates.noindex/YOURPROJECT.build/Release-SDK/TARGET.build/DerivedSources/TARGET_vers.c normal arm64 c com.apple.compilers.llvm.clang.1_0.compiler (in target 'TARGET' from project 'YOURPROJECT')
These two lines are the real meat of your problem. Your bundle, which formerly had no binary files in it (only PNGs, XIBs, and other resources), now has a binary file. One that was created by Xcode. Because this binary was created as part of a resource bundle target, it's compiled as a CFBundleExecutable using the -bundle flag, which is incompatible with ENABLE_BITCODE. Instead of disabling bitcode, though, you should prevent this binary from being generated in the first place.
This binary is being created by Apple Generic Versioning. To get rid of it, go to your build settings tab (on your resource bundle target), click the "all" button to see all settings, then search for "versioning system". Change this from "Apple Generic" to "None". Resource bundles do not properly support versioning.

How to build an Appcelerator Titanium iOS Module that requires a CocoaPods pod

I would like to build a native iOS module that requires a CocoaPods pod (https://cocoapods.org/pods/NearbyMessages).
I created a new module using the Titanium Command Line Interface:
ti create --type=module --platforms=ios ...
I followed the instructions from CocoaPods (https://guides.cocoapods.org/using/using-cocoapods.html) to create a Podfile:
platform :ios, '9.0'
target 'MyModule' do
pod 'NearbyMessages'
end
I placed the Podfile into the "iphone" directory of my iOS module directory:
MyModule
- LICENCE
- README
- assets
- documentation
- example
- iphone
- Podfile
- ...
- timodule.xml
- titanium.xcconfig
I installed the pod using the following command:
pod install
I opened XCode with the newly created *.xcworkspace file and added the following line to the end of the titanium.xcconfig file:
#include "Pods/Target Support Files/Pods-MyModule/Pods-MyModule.debug.xcconfig"
But unfortunately this leads to several errors, like:
"'Ti.Module.h' file not found" in the header file of my module
several "cannot use 'super' because it is a root class" in the implementation file of my module
I tried different variations of including the Pods config file but none of them were successful.
Can anybody please tell me how a correct XCode setup should look like to use the NearbyMessages pod in a native iOS module?
Thanks in advance and best regards!
The build.py file needs to be updated to use the workspace file instead. Inside the build_module method, add the -workspace and -scheme parameters to xcodebuild. The lines should look like this:
rc = os.system("xcodebuild -workspace %s.xcworkspace -scheme %s -sdk iphoneos -configuration Release" %(manifest['name'],manifest['name']))
rc = os.system("xcodebuild -workspace %s.xcworkspace -scheme %s -sdk iphonesimulator -configuration Release" %(manifest['name'],manifest['name']))
After making this change, python build.py should work successfully.
I'm just at the point of figuring this out for myself, so there may need to be more steps, but that got me past the point you are at.

ld: framework not found AFNetworking

I get linking error when trying to compile iOS project from terminal with Xcode 7.1.1:
xcodebuild -project MyProject.xcodeproj -configuration Debug -target MyProject build
As result I receive next error:
ld: framework not found AFNetworking
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is my pod file:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target "MyProject" do
pod "AFNetworking", "~> 2.0"
pod 'GoogleMaps'
pod 'MONActivityIndicatorView'
pod 'NYXImagesKit'
pod 'MagicalRecord'
pod 'FBSDKCoreKit'
pod 'FBSDKShareKit'
pod 'FBSDKLoginKit'
pod 'Countly'
end
xcodeproj 'MyProject'
I also tried adding link_with but get the same error. How to fix the problem above?
You need to build using the workspace generated by CocoaPods:
xcodebuild -workspace MyProject.xcworkspace -configuration Debug -scheme MyProject build
If you build just the project, xcodebuild does not see the dependency on the Pods project. Note that you have to use a scheme when building a workspace rather than a target. This means if you are building on a build server you will need to mark your scheme as shared in the scheme editor.

Resources