Why Do We Use Use_Frameworks! in Cocoapods

use_frameworks! for only some pods or swift pods

When JSBridge init, it will add some "UserScripts" to webview, which source is loaded from [NSBundle mainBundle] in previous version. But if it's in a framework, the resource files is in the framework bundle instead of mainBundle.

So the fix is in WBWebViewConsoleDefines

replace this

inline static NSBundle * WBWebBrowserConsoleBundle()
{
return [NSBundle bundleWithPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] bundlePath], @"WBWebBrowserConsole.bundle"]];
}

with

inline static NSBundle * WBWebBrowserConsoleBundle()
{
return [NSBundle bundleWithPath:[NSString stringWithFormat:@"%@/%@", [NSBundle bundleForClass:[WBWebViewConsole class]], @"WBWebBrowserConsole.bundle"]];
}

Actually the author has released new version it also has the fix

pod 'WBWebViewConsole', '~> 1.0.2’

  1. pod install
  2. restart Xcode and clean your project
  3. build and run again

Note: Its not possible. if you use_frameworks! everything become dynamic framework.

use_framework vs use_native_modules

Guess I have understand both the difference (please correct me if my understanding is incorrect),

For use_frameworks! please read here as it has already describe what it's for.

For use_native_modules!, it's actually being use in React Native 0.60 and above for auto-linking. With the command specified in podfile, all the new dependency appended to project do not require developer to append new dependency's podspec into podfile. It will link automatically when you run pod install command.

I have been appending all the podspecs myself ever since I upgraded to RN0.60

Sample podfile

platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target 'example' do
# Pods for example
pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/'
pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

target 'exampleTests' do
inherit! :search_paths
# Pods for testing
end

use_native_modules!
end

target 'example-tvOS' do
# Pods for example-tvOS

target 'example-tvOSTests' do
inherit! :search_paths
# Pods for testing
end

end

use_framework! in Podfile caused 'React/RCTBridgeDelegate.h' not found

TLDR

Append $(inherited) at Framework Search Paths .



Explanation

Apparently, when we apply use_frameworks! at Podfile. Our Xcode project will replace libPods-{projectName}.a with Pods_{projectName}.framework.

Since our project is relying on Frameworks to build, we have to append $(inherited) to Framework Search Paths at Target > Build Settings > Search Paths > Framework Search Paths. This will inherit the build settings from project level to target level. Read more here.

adding 'use_frameworks!' in podfile is breaking app

At this moment Xcode does not allow that. use_frameworks works only with swift pods or libraries. If you add an objective C library you need to use the bridging header, therefore you need to remove the use_frameworks instruction in order to make it work. The only work around I found is to only import through pods the objective C libraries and the swift libraries you can add them manually. You can copy the classes names and content and use them as if you would have created them.

Using cocoapods without use_frameworks! in Swift

Past

Up to CocoaPods 1.4.x (included), it was NOT possible to use CocoaPods with Swift code without use_frameworks!.

Present: 1.x.x and above

Nowadays, with CocoaPods 1.x.x (I verified it with 1.4.0), it's common to use use_frameworks! for both Swift and ObjC projects: it allows for a mix of the two languages in any way you want without issues:

  • You'll be able to use a Swift dependency in an Objective-C project.
  • You'll be able to use an Objective-C dependency in a Swift project.

Present: 1.5.x and above

Nowadays, CocoaPods 1.5.0 supports integrating swift pods as static libraries. Try it (sudo gem install cocoapods) and enjoy removing use_frameworks! from your Podfile.


Note that for iOS:

  • Apple requires Xcode 10.1 minimum, which is only well supported starting CocoaPods 1.6.0, so don't bother using older versions of CocoaPods.
  • Apple will require Xcode 11 minimum in April 2020, for which I would only use CocoaPods 1.7.5 or newer, together with xcodeproj 1.13.0 or newer.


Related Topics



Leave a reply



Submit