Skip to content

Commit

Permalink
ios build: Start using CocoaPods again.
Browse files Browse the repository at this point in the history
There was an attempt to use CocoaPods in aded466, 2017-03-19.

That was removed in 4096e71, 2017-07-18.

Some cleanup was done in 861744b, 2020-02-05.

To paraphrase Greg on zulip#3983:

CocoaPods is a tool for managing iOS libraries. It means instead of
having an `.xcodeproj` file for every library, and manually
connecting them to your app's own `.xcodeproj`, a separate
`Pods.xcodeproj` is generated from a simple, declarative Podfile,
and all you have to do to update or add dependencies is edit the
Podfile and run `pod install`. Many people use it in their React
Native apps, but there some tricky bits that have impeded universal
adoption.

RN v0.60 signals a full embrace of the use of CocoaPods by RN, by
making it work more smoothly. CocoaPods becomes required in v0.61.

Originally, we were going to start using CocoaPods as part of the RN
v0.60 upgrade, but we have a fresh reason to want to use CocoaPods,
with its own deadline: zulip#3964, Apple auth. Someone has made a handy
Expo package to handle Apple auth, but we can't use Expo packages
without either fully committing to using the Expo SDK (a dramatic
step) or using a package called react-native-unimodules, which lets
you select individual Expo packages. react-native-unimodules
requires the use of CocoaPods.

So, use CocoaPods now. Note that the Podfile will have to be
different when we upgrade to RN v0.60.0; see the parent for details.

Unfortunately, this has to be one giant commit instead of multiple
commits. From experimentation, this seems to be the minimal set of
changes that doesn't break functionality, which makes sense
intuitively when changing entirely between management strategies for
(somewhat) complex dependencies. We were also prompted to try this
strategy from solution 3 at this SO post:
https://stackoverflow.com/questions/53312887/error-on-archiving-react-native-app-in-xcode-multiple-commands-produce-libyog/55328241#5532824
But Greg has the most plausible theory for the actual reason why
this is necessary:

"""
One possibility is something like: we were getting React, as a
whole, from the direct references in the Xcode config; and so that
version of the built React library had versions of RCTImageView etc.
only when those were configured through RCTImage.xcodeproj etc., via
direct references to those in our Xcode config.

Whereas the built React library from React.podfile and our Podspec
had the RCTImageView that was built due to the RCTImage subspec in
our Podfile... but perhaps we just didn't get that one because it
had to compete with the libReact.a (or whatever) from our Xcode
config. And once we no longer had the latter, we started getting the
former instead.
"""

We started with a Podfile based on the example
Podfile given for react-native v0.59, at
https://github.com/facebook/react-native-website/blob/ded79d2cf4456d8b1a4f67c2cdc1391789e70617/docs/integration-with-existing-apps.md.
(That doc isn't live on the react-native docs website because of
facebook/react-native-website#1603.)

Then, we realized that more RN-provided libraries were present in
our Xcode config, so we added those.

We also added a number of dependencies that depend on React Native
(react-native-image-picker, etc.).
`grep -Rlw 'React' --include=\*.podspec node_modules/` verified
that they do indeed depend on the 'React' pod, which is React
Native.

Also, add a build phase to start Metro. For some reason that we
haven't found yet, Metro doesn't start automatically after the
switch to CocoaPods. It seems that this was recognized by the RN
maintainers as they were updating the template app to switch to
CocoaPods. They separated the addition of this build phase into its
own commit,
facebook/react-native@1f719ae43,
but it doesn't mention the reason it was added.

In that commit, the name "Start Packager" was used. Here, we use
"Start Metro" because a proper noun is more helpful, and this name
is what RN uses in a more recent commit,
facebook/react-native@e636eb60d, which
creates a RNTesterPods project and workspace for testing some
aspects of CocoaPods separately. (It's not clear without further
digging what aspects those are, but it hasn't been relevant to using
CocoaPods on RN v0.59.10.)

Notes on individual dependencies:

RNDeviceInfo (react-native-device-info):

The install instructions at
https://github.com/react-native-community/react-native-device-info#manual
for RN v0.59.0 using CocoaPods wrongly say not to use CocoaPods (by
omitting the line in the Podfile). The author's comment at
react-native-device-info/react-native-device-info#748 (comment)
suggests that he never found the successful strategy of doing an
all-at-once adoption of CocoaPods, as we do here, and rather
concluded that a bug was caused by RN v0.59.x having shaky support
for CocoaPods. Including the pod works fine.

Fixes: zulip#3983
  • Loading branch information
Chris Bobbe authored and gnprice committed Apr 3, 2020
1 parent f475bc4 commit 33f4b41
Show file tree
Hide file tree
Showing 12 changed files with 456 additions and 1,568 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Suppress noisy generated files in diffs.
yarn.lock -diff
src/webview/js/generatedEs3.js -diff
ios/Podfile.lock -diff

# The flow-typed files that aren't pure generated noise have names with at
# least a major version number -- like `redux_v4.x.x.js`.
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ npm-debug.log
# Test files
/pirlo-cli

# CocoaPods (not currently used)
# CocoaPods
/ios/Pods

# Transifex, for a maintainer syncing translations up and down
Expand Down
18 changes: 16 additions & 2 deletions docs/howto/build-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ Native upstream on
You want the tab "React Native CLI Quickstart"; the "Expo CLI Quickstart" does
not apply.

If you're starting with iOS development, be sure to install CocoaPods,
as the guide instructs. After you've done that, run
`cd ios && pod install && cd ..`.

Continue those instructions until you can run the Zulip Mobile app
with either `react-native run-android` or `react-native run-ios`.
You'll want to be able to use both an emulator and a physical device; but
Expand Down Expand Up @@ -239,7 +243,7 @@ android` there, may give clearer error messages for debugging.
[rn-installation]: https://facebook.github.io/react-native/docs/getting-started.html


### Build failure in `react-native-screens` or at `new RNNotificationsPackage()`
### Build failure after running `react-native link`

When trying to build the Android app, if you get an error like this:

Expand Down Expand Up @@ -268,6 +272,15 @@ or like this:
[...]
```

or, when trying to build the iOS app, if you get several errors like
this:

```
Multiple commands produce '/Users/jappleseed/Library/Developer/Xcode/DerivedData/ZulipMobile-gdifomwwvfiwepckshlwoludvdct/Build/Products/Debug-iphonesimulator/ZulipMobile.app/Fontisto.ttf':
1) Target 'ZulipMobile' (project 'ZulipMobile') has copy command from '/Users/jappleseed/dev/zulip-mobile/node_modules/react-native-vector-icons/Fonts/Fontisto.ttf' to '/Users/jappleseed/Library/Developer/Xcode/DerivedData/ZulipMobile-gdifomwwvfiwepckshlwoludvdct/Build/Products/Debug-iphonesimulator/ZulipMobile.app/Fontisto.ttf'
2) That command depends on command in Target 'ZulipMobile' (project 'ZulipMobile'): script phase “[CP] Copy Pods Resources”
```

then check that `git status` shows you're running unmodified code from
our repo. These errors can be caused by the modifications made if you
run the command `react-native link`.
Expand All @@ -280,7 +293,8 @@ the project's version-control repo -- and not a build step. We don't
use it as a build step.

If you've run `react-native link`, you can discard the edits it made
(along with any other edits you've made) by running `git reset --hard`.
(along with any other edits you've made!) by running
`git reset --hard`.


### Build failure in `:app:buildDebugStaticWebviewAssets`
Expand Down
28 changes: 16 additions & 12 deletions docs/howto/ios-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ this tab.

## Other commands

* `cd ios && pod install && cd ..` - if you've already run `yarn`,
installs native iOS dependencies to match the Podfile.lock

* `yarn ios-min` - runs in an iOS simulator in the minimally supported device
(currently iPhone 5S)

Expand Down Expand Up @@ -42,15 +45,16 @@ and choose it as your `Signing > Team` for both ZulipMobile and ZulipMobileTests
### Tips when running on your iOS device
When you change the BundleIdentifier and Team (required in order to run on a device),
it **will** modify your `.pbxproj` file, which you do **not** want unless you intend
to. For instance, if you linking a new dependency, your `.pbxproj` will be modified to
reflect the new changes.

If you are simply testing it on the iOS device, simply do not stage the said file to
be committed. On the other hand, if you are also adding a dependency, it is recommended
that you first `git commit` the dependency link modification itself, and then start
developing. This way, when you stage your intended changes, you can do a `git reset
path/to/.pbxproj` to discard any changes relating to the modification of the BundleIdentifier
and Team, and then continue to commit the rest of the files. When you prepare to push your
changes, you can just squash the initial commit with your later commits to retain a clean
commit history. This way, you won't have to deal with any merge conflicts or manual
deletion of the lines in your `.pbxproj` when you submit your code for a review.
to.

If you are simply testing it on the iOS device, simply do not stage
the said file to be committed.

If other changes to the `.pbxproj` file are needed (and they shouldn't
usually be, especially after we started managing our iOS dependencies
with CocoaPods), it's recommended that you put them in their own
commit, first, and leave the BundleIdentifier and Team changes
unstaged. Later, you can always [squash that commit with other
commits][fixing-commits], if appropriate.

[fixing-commits]: https://zulip.readthedocs.io/en/latest/git/fixing-commits.html
55 changes: 55 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This should match the iOS Deployment Target
# (project > ZulipMobile > Info in Xcode)
platform :ios, '10.3'

# This list will need to change for RN >= v0.60. If you're changing it
# for any other reason, first look at the example Podfile for v0.59 at
# https://github.com/facebook/react-native-website/blob/ded79d2cf/docs/integration-with-existing-apps.md#configuring-cocoapods-dependencies.
target 'ZulipMobile' do
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'CxxBridge',
'DevSupport',
'RCTText',
'RCTNetwork',
'RCTWebSocket',
'RCTAnimation',
'RCTImage',
'RCTPushNotification',
'ART',
'RCTAnimation',
'RCTCameraRoll',
'RCTActionSheet',
'RCTGeolocation',
'RCTLinkingIOS', # RCTLinking?
'RCTSettings',
'RCTVibration',
]
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'

# Pods we need that depend on React Native
pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'
pod 'react-native-notifications', :path => '../node_modules/react-native-notifications'
pod 'RNSound', :path => '../node_modules/react-native-sound'
pod 'rn-fetch-blob', :path => '../node_modules/rn-fetch-blob'
pod 'react-native-photo-view', :path => '../node_modules/react-native-photo-view'
pod 'react-native-safe-area', path: '../node_modules/react-native-safe-area'
pod 'react-native-orientation', :path => '../node_modules/react-native-orientation'
pod 'react-native-image-picker', :path => '../node_modules/react-native-image-picker'
pod 'react-native-webview', :path => '../node_modules/react-native-webview'
pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
pod 'RNSentry', :path => '../node_modules/@sentry/react-native'
pod 'react-native-safari-view', :path => '../node_modules/react-native-safari-view'
pod 'react-native-netinfo', :path => '../node_modules/@react-native-community/netinfo'
pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'
pod 'react-native-simple-toast', :path => '../node_modules/react-native-simple-toast'

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

end
220 changes: 220 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
PODS:
- boost-for-react-native (1.63.0)
- DoubleConversion (1.1.6)
- Folly (2018.10.22.00):
- boost-for-react-native
- DoubleConversion
- glog
- glog (0.3.5)
- React (0.59.10):
- React/Core (= 0.59.10)
- react-native-image-picker (0.14.3):
- React
- react-native-netinfo (3.2.1):
- React
- react-native-notifications (1.5.0):
- React
- react-native-orientation (3.1.3):
- React
- react-native-photo-view (1.5.2):
- React
- react-native-safari-view (1.0.0):
- React
- react-native-safe-area (0.4.4):
- React
- react-native-simple-toast (0.1.1):
- React
- react-native-webview (5.12.1):
- React
- React/ART (0.59.10):
- React/Core
- React/Core (0.59.10):
- yoga (= 0.59.10.React)
- React/CxxBridge (0.59.10):
- Folly (= 2018.10.22.00)
- React/Core
- React/cxxreact
- React/jsiexecutor
- React/cxxreact (0.59.10):
- boost-for-react-native (= 1.63.0)
- DoubleConversion
- Folly (= 2018.10.22.00)
- glog
- React/jsinspector
- React/DevSupport (0.59.10):
- React/Core
- React/RCTWebSocket
- React/fishhook (0.59.10)
- React/jsi (0.59.10):
- DoubleConversion
- Folly (= 2018.10.22.00)
- glog
- React/jsiexecutor (0.59.10):
- DoubleConversion
- Folly (= 2018.10.22.00)
- glog
- React/cxxreact
- React/jsi
- React/jsinspector (0.59.10)
- React/RCTActionSheet (0.59.10):
- React/Core
- React/RCTAnimation (0.59.10):
- React/Core
- React/RCTBlob (0.59.10):
- React/Core
- React/RCTCameraRoll (0.59.10):
- React/Core
- React/RCTImage
- React/RCTGeolocation (0.59.10):
- React/Core
- React/RCTImage (0.59.10):
- React/Core
- React/RCTNetwork
- React/RCTLinkingIOS (0.59.10):
- React/Core
- React/RCTNetwork (0.59.10):
- React/Core
- React/RCTPushNotification (0.59.10):
- React/Core
- React/RCTSettings (0.59.10):
- React/Core
- React/RCTText (0.59.10):
- React/Core
- React/RCTVibration (0.59.10):
- React/Core
- React/RCTWebSocket (0.59.10):
- React/Core
- React/fishhook
- React/RCTBlob
- rn-fetch-blob (0.10.6):
- React/Core
- RNCAsyncStorage (1.6.3):
- React
- RNDeviceInfo (0.21.5):
- React
- RNSentry (1.0.9):
- React
- Sentry (~> 4.4.0)
- RNSound (0.10.12):
- React/Core
- RNSound/Core (= 0.10.12)
- RNSound/Core (0.10.12):
- React/Core
- RNVectorIcons (6.6.0):
- React
- Sentry (4.4.3):
- Sentry/Core (= 4.4.3)
- Sentry/Core (4.4.3)
- yoga (0.59.10.React)

DEPENDENCIES:
- DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
- Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`)
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
- react-native-image-picker (from `../node_modules/react-native-image-picker`)
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
- react-native-notifications (from `../node_modules/react-native-notifications`)
- react-native-orientation (from `../node_modules/react-native-orientation`)
- react-native-photo-view (from `../node_modules/react-native-photo-view`)
- react-native-safari-view (from `../node_modules/react-native-safari-view`)
- react-native-safe-area (from `../node_modules/react-native-safe-area`)
- react-native-simple-toast (from `../node_modules/react-native-simple-toast`)
- react-native-webview (from `../node_modules/react-native-webview`)
- React/ART (from `../node_modules/react-native`)
- React/Core (from `../node_modules/react-native`)
- React/CxxBridge (from `../node_modules/react-native`)
- React/DevSupport (from `../node_modules/react-native`)
- React/RCTActionSheet (from `../node_modules/react-native`)
- React/RCTAnimation (from `../node_modules/react-native`)
- React/RCTCameraRoll (from `../node_modules/react-native`)
- React/RCTGeolocation (from `../node_modules/react-native`)
- React/RCTImage (from `../node_modules/react-native`)
- React/RCTLinkingIOS (from `../node_modules/react-native`)
- React/RCTNetwork (from `../node_modules/react-native`)
- React/RCTPushNotification (from `../node_modules/react-native`)
- React/RCTSettings (from `../node_modules/react-native`)
- React/RCTText (from `../node_modules/react-native`)
- React/RCTVibration (from `../node_modules/react-native`)
- React/RCTWebSocket (from `../node_modules/react-native`)
- rn-fetch-blob (from `../node_modules/rn-fetch-blob`)
- "RNCAsyncStorage (from `../node_modules/@react-native-community/async-storage`)"
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
- "RNSentry (from `../node_modules/@sentry/react-native`)"
- RNSound (from `../node_modules/react-native-sound`)
- RNVectorIcons (from `../node_modules/react-native-vector-icons`)
- yoga (from `../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
trunk:
- boost-for-react-native
- Sentry

EXTERNAL SOURCES:
DoubleConversion:
:podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec"
Folly:
:podspec: "../node_modules/react-native/third-party-podspecs/Folly.podspec"
glog:
:podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec"
React:
:path: "../node_modules/react-native"
react-native-image-picker:
:path: "../node_modules/react-native-image-picker"
react-native-netinfo:
:path: "../node_modules/@react-native-community/netinfo"
react-native-notifications:
:path: "../node_modules/react-native-notifications"
react-native-orientation:
:path: "../node_modules/react-native-orientation"
react-native-photo-view:
:path: "../node_modules/react-native-photo-view"
react-native-safari-view:
:path: "../node_modules/react-native-safari-view"
react-native-safe-area:
:path: "../node_modules/react-native-safe-area"
react-native-simple-toast:
:path: "../node_modules/react-native-simple-toast"
react-native-webview:
:path: "../node_modules/react-native-webview"
rn-fetch-blob:
:path: "../node_modules/rn-fetch-blob"
RNCAsyncStorage:
:path: "../node_modules/@react-native-community/async-storage"
RNDeviceInfo:
:path: "../node_modules/react-native-device-info"
RNSentry:
:path: "../node_modules/@sentry/react-native"
RNSound:
:path: "../node_modules/react-native-sound"
RNVectorIcons:
:path: "../node_modules/react-native-vector-icons"
yoga:
:path: "../node_modules/react-native/ReactCommon/yoga"

SPEC CHECKSUMS:
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
DoubleConversion: bb338842f62ab1d708ceb63ec3d999f0f3d98ecd
Folly: de497beb10f102453a1afa9edbf8cf8a251890de
glog: aefd1eb5dda2ab95ba0938556f34b98e2da3a60d
React: 36d0768f9e93be2473b37e7fa64f92c1d5341eef
react-native-image-picker: 3693786b3d5958c8f71deed66ec068b323565e0d
react-native-netinfo: 0da34082d2cec3100c9b5073bb217e35f1142bdd
react-native-notifications: ce37363008fe2d6a226da4e721eace23b6ae3ad9
react-native-orientation: f1caf84d65f1a4fd4511a18f2b924e634ad7a628
react-native-photo-view: 63e9e61da873531f931008b545d8d10c5373ddf8
react-native-safari-view: 955d7160d159241b8e9395d12d10ea0ef863dcdd
react-native-safe-area: 5fce5242419932bc05656f31bc5f0716e30be0f6
react-native-simple-toast: 1fc69d83c24279ed4f9624352551a5a3406678a2
react-native-webview: 5036ed4a973ad1deeeff118262d2df7b60b3419d
rn-fetch-blob: 766f85cabd2992300dfa1be2bc9e4e258abc6f04
RNCAsyncStorage: 3c304d1adfaea02ec732ac218801cb13897aa8c0
RNDeviceInfo: e7c5fcde13d40e161d8a27f6c5dc69c638936002
RNSentry: 2803ba8c8129dcf26b79e9b4d8c80168be6e4390
RNSound: a1d01988e043aed5dbb476c2152b5ffb02446750
RNVectorIcons: 0bb4def82230be1333ddaeee9fcba45f0b288ed4
Sentry: 14bdd673870e8cf64932b149fad5bbbf39a9b390
yoga: 684513b14b03201579ba3cee20218c9d1298b0cc

PODFILE CHECKSUM: 882347e8d497f7575a47b2d21471f49b106eed82

COCOAPODS: 1.8.4
Loading

0 comments on commit 33f4b41

Please sign in to comment.