Skip to content

Instantly share code, notes, and snippets.

@alloy

alloy/Podfile

Last active Feb 28, 2020
Embed
What would you like to do?
Example of a Podfile that builds React Native without integrating into an app

As React Native’s sources are bundled with the npm packages, it may be easiest to bootstrap your setup by generating a RN app and then removing all the parts you don’t need.

$ react-native init TestStandaloneRNBuilds
[…]

$ cd TestStandaloneRNBuilds/ios

$ rm -rf TestStandaloneRNBuilds*

$ edit Podfile

Update with contents of Podfile example.

$ pod install
Analyzing dependencies
Downloading dependencies
Generating Pods project
Skipping User Project Integration
Pod installation complete! There are 28 dependencies from the Podfile and 26 total pods installed.

[!] The abstract target Pods is not inherited by a concrete target, so the following dependencies won't make it into any targets in your project:
[…]

Now you are left with a Pods/Pods.xcodeproj that is able to build all the deps, which you can do in any way you would normally build Xcode projects. E.g.:

$ xcodebuild -project Pods/Pods.xcodeproj -configuration Debug -target React
[…]

$ tree build/Debug-iphonesimulator/
build/Debug-iphonesimulator/
├── DoubleConversion
│   └── libDoubleConversion.a
├── Folly
│   └── libFolly.a
├── React-Core
│   └── libReact-Core.a
├── React-RCTActionSheet
│   └── libReact-RCTActionSheet.a
├── React-RCTAnimation
│   └── libReact-RCTAnimation.a
├── React-RCTBlob
│   └── libReact-RCTBlob.a
├── React-RCTImage
│   └── libReact-RCTImage.a
├── React-RCTLinking
│   └── libReact-RCTLinking.a
├── React-RCTNetwork
│   └── libReact-RCTNetwork.a
├── React-RCTSettings
│   └── libReact-RCTSettings.a
├── React-RCTText
│   └── libReact-RCTText.a
├── React-RCTVibration
│   └── libReact-RCTVibration.a
├── React-cxxreact
│   └── libReact-cxxreact.a
├── React-jsi
│   └── libReact-jsi.a
├── React-jsiexecutor
│   └── libReact-jsiexecutor.a
├── React-jsinspector
│   └── libReact-jsinspector.a
├── Yoga
│   └── libYoga.a
└── glog
    └── libglog.a

Be sure to leverage the xcconfig files generated by CocoaPods to know how to integrate these libs into your application targets:

$ tree -P '*.xcconfig' Pods/Target\ Support\ Files/
Pods/Target\ Support\ Files/
├── DoubleConversion
│   └── DoubleConversion.xcconfig
├── FBLazyVector
│   └── FBLazyVector.xcconfig
├── FBReactNativeSpec
│   └── FBReactNativeSpec.xcconfig
├── Folly
│   └── Folly.xcconfig
├── RCTRequired
│   └── RCTRequired.xcconfig
├── RCTTypeSafety
│   └── RCTTypeSafety.xcconfig
├── React
│   └── React.xcconfig
├── React-Core
│   └── React-Core.xcconfig
├── React-CoreModules
│   └── React-CoreModules.xcconfig
├── React-RCTActionSheet
│   └── React-RCTActionSheet.xcconfig
├── React-RCTAnimation
│   └── React-RCTAnimation.xcconfig
├── React-RCTBlob
│   └── React-RCTBlob.xcconfig
├── React-RCTImage
│   └── React-RCTImage.xcconfig
├── React-RCTLinking
│   └── React-RCTLinking.xcconfig
├── React-RCTNetwork
│   └── React-RCTNetwork.xcconfig
├── React-RCTSettings
│   └── React-RCTSettings.xcconfig
├── React-RCTText
│   └── React-RCTText.xcconfig
├── React-RCTVibration
│   └── React-RCTVibration.xcconfig
├── React-cxxreact
│   └── React-cxxreact.xcconfig
├── React-jsi
│   └── React-jsi.xcconfig
├── React-jsiexecutor
│   └── React-jsiexecutor.xcconfig
├── React-jsinspector
│   └── React-jsinspector.xcconfig
├── ReactCommon
│   └── ReactCommon.xcconfig
├── Yoga
│   └── Yoga.xcconfig
├── boost-for-react-native
│   └── boost-for-react-native.xcconfig
└── glog
    └── glog.xcconfig
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
install! 'cocoapods', :integrate_targets => false
platform :ios, '9.0'
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'
@erlong16

This comment has been minimized.

Copy link

@erlong16 erlong16 commented Feb 27, 2020

What about the Flipper pods?

@alloy

This comment has been minimized.

Copy link
Owner Author

@alloy alloy commented Feb 27, 2020

You can just copy those over like all the rest, e.g. from https://github.com/facebook/react-native/blob/0.62-stable/template/ios/Podfile

@erlong16

This comment has been minimized.

Copy link

@erlong16 erlong16 commented Feb 27, 2020

Hrm. I asked because I tried adding:

`def add_flipper_pods!
version = '~> 0.30.2'
pod 'FlipperKit', version, :configuration => 'Debug'
pod 'FlipperKit/FlipperKitLayoutPlugin', version, :configuration => 'Debug'
pod 'FlipperKit/SKIOSNetworkPlugin', version, :configuration => 'Debug'
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', version, :configuration => 'Debug'
pod 'FlipperKit/FlipperKitReactPlugin', version, :configuration => 'Debug'
end

# Post Install processing for Flipper
def flipper_post_install(installer)
installer.pods_project.targets.each do |target|
if target.name == 'YogaKit'
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.1'
end
end
end
end`

And...

`use_native_modules!

#
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
add_flipper_pods!
post_install do |installer|
flipper_post_install(installer)
end`

To the exsmple above. I get an error now:

[!] Invalid Podfilefile: undefined method[]' for nil:NilClass.

\ # -------------------------------------------
\ #

use_native_modules!
\ #
\ # -------------------------------------------`

@erlong16

This comment has been minimized.

Copy link

@erlong16 erlong16 commented Feb 27, 2020

What I chose to do is:

a) Remove: use_native_modules!
b) Remove every: , :configuration => 'Debug'

That seems to do the job.

@alloy

This comment has been minimized.

Copy link
Owner Author

@alloy alloy commented Feb 28, 2020

Makes sense 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.