Skip to content

Commit

Permalink
ios build: Enable "autolinking".
Browse files Browse the repository at this point in the history
Part of the RN v0.59 -> v0.60 upgrade [1]. (Or, at least, RN and
most library maintainers assume it is done as such.) This must
happen at or after the upgrade commit because autolinking is a new
feature.

Just like the previous commit, but for iOS.

1. Following the doc [2] as before, unlink everything. Again, with a
   script, but this time, only for iOS:

   ```
   for dep in `tools/deps`; do
     react-native unlink --platforms=ios "$dep"
   done
   ```

   Exclude the same set of Sentry changes as we did in this step for
   Android. Also, exclude a change to our Info.plist that would
   remove the "Fonts provided by application", a.k.a., `UIAppFonts`.
   This is a setup step [3] that we need to keep.

   So, we're left with the removal of all items from the "Pods we
   need that depend on React Native" list.

   Additionally, remove "libz" from our Xcode config. It was put
   there by Sentry, as a consequence of running `react-native link`
   before we were using CocoaPods. But Sentry expresses the same
   dependency in `Sentry.podspec`. So, having it in our Xcode config
   is redundant. [4]

2. Make the changes recommended by these commits in
   `facebook/react-native`. They follow an A, revert-A, A' pattern:

   - 261197d85 Implement changes to enable native modules auto
   linking (#24506)

   - da7d3dfc7 Partially back out #24506, fixing iOS e2e tests
   (#24788)

   - 86a97e783 – Bring back autolinking to the iOS template (#25314)

   It simply imports and runs a command, `use_native_modules`.

3. Now, go back to `react-native-unimodules` and follow the ">=
   0.60" branch of the "Configure iOS" instructions. Turns out that
   no changes are needed here; the differences in expressing our
   React pod dependencies were handled in the main RN v0.60 upgrade
   commit.

4. Move the two deps under "RN-dependent Pods that we could include,
   but we've decided not to" into the `react-native.config.js`.

5. Add a workaround in `tools/postinstall` for an issue [5] with
   running `pod install` from the root directory with
   `--project-directory=ios`.

   We tried the workaround suggested in that issue, where we have
   `use_native_modules!(".")` in the Podfile and still call
   `pod install --project-directory=ios` from the root directory.
   (This might have led to a cleaner solution, where we pass "." in
   the postinstall case, and pass nothing otherwise.) But we got
   this error, which isn't addressed in that issue, and doesn't seem
   easy to fix without changes to `native_modules.rb`:

   ```
   [!] No podspec found for `RNCAsyncStorage` in `./node_modules/@react-native-community/async-storage`
   ```

   It's plausible that those investigating this issue were only
   testing with a template project that didn't have RN-dependent
   pods like RNCAsyncStorage, so, never saw this error.

6. Run `pod install` and see that the only change to
   `ios/Podfile.lock` is in the checksum. So, job done.

Closes: #4026

[1]: https://react-native-community.github.io/upgrade-helper/?from=0.59.10&to=0.60.6

[2]: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md

[3]: https://github.com/oblador/react-native-vector-icons#option-manually

[4]: There's some uncertainty here; we're not seeing `z` or `libz`
     in ios/Pods/Pods.xcodeproj/project.pbxproj after running `pod
     install`, with or without autolinking. But it seems to work.
     More discussion at
     #4026 (comment)
     and
     https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/RN.20autolinking/near/884333.

[5]: react-native-community/cli#657
  • Loading branch information
chrisbobbe committed Jun 1, 2020
1 parent 4107915 commit c25981b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
28 changes: 4 additions & 24 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# (project > ZulipMobile > Info in Xcode)
platform :ios, '10.3'

require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/react-native-unimodules/cocoapods.rb'

target 'ZulipMobile' do
Expand Down Expand Up @@ -31,30 +32,9 @@ target 'ZulipMobile' do
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'

# RN-dependent Pods that we could include, but we've decided not to

# iOS file uploads aren't supported yet.
# pod 'react-native-document-picker', :path => '../node_modules/react-native-document-picker'

# We haven't enabled `react-native-screens` yet, that's #4111.
# pod 'RNScreens', :path => '../node_modules/react-native-screens'
# "Autolinking": automatically link pods that depend on React
# Native, unless omitted in our own `react-native.config.js`.
use_native_modules!

# unimodules provides Expo packages individually.
use_unimodules!
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,6 @@ SPEC CHECKSUMS:
UMTaskManagerInterface: 1e70fe58b872355f0ecb44fb81bb1a16484047f0
yoga: 5079887aa3e4c62142d6bcee493022643ee4d730

PODFILE CHECKSUM: 9e2b9e03f89ac5303457ca65f322487d478edb51
PODFILE CHECKSUM: 35e31db914557542fa277c2ec99e983927f39658

COCOAPODS: 1.9.1
4 changes: 0 additions & 4 deletions ios/ZulipMobile.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
3EE5D55E2431F20B7F410CFE /* libPods-ZulipMobileTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 338F4382FA4C3F52F95A1F5B /* libPods-ZulipMobileTests.a */; };
42689E9C23466FF7007540AA /* webview in Resources */ = {isa = PBXBuildFile; fileRef = 42689E9B23466FF7007540AA /* webview */; };
840D44FCCBB14F97B77D9443 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = B2BC2F95A8684C44BAFA7B11 /* libz.tbd */; };
A148FEFC1E9D8CB900479280 /* zulip.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = A148FEFB1E9D8CB900479280 /* zulip.mp3 */; };
C091D09FD11FDDB8E939257D /* libPods-ZulipMobile.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 74F3CD22CB932FA7EEE0BB66 /* libPods-ZulipMobile.a */; };
CFA67D201EC23BCB0070048E /* UtilManager.m in Sources */ = {isa = PBXBuildFile; fileRef = CFA67D1F1EC23BCB0070048E /* UtilManager.m */; };
Expand Down Expand Up @@ -52,7 +51,6 @@
66E34CC6219226D10091B852 /* ZulipMobile-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ZulipMobile-Bridging-Header.h"; sourceTree = "<group>"; };
74F3CD22CB932FA7EEE0BB66 /* libPods-ZulipMobile.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ZulipMobile.a"; sourceTree = BUILT_PRODUCTS_DIR; };
A148FEFB1E9D8CB900479280 /* zulip.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = zulip.mp3; sourceTree = "<group>"; };
B2BC2F95A8684C44BAFA7B11 /* libz.tbd */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
CF6CFE2C1E7DC55100F687C7 /* Build-Phases */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "Build-Phases"; sourceTree = "<group>"; };
CFA67D1F1EC23BCB0070048E /* UtilManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UtilManager.m; path = ZulipMobile/UtilManager.m; sourceTree = "<group>"; };
CFA67D211EC23BDD0070048E /* UtilManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = UtilManager.h; path = ZulipMobile/UtilManager.h; sourceTree = "<group>"; };
Expand All @@ -75,7 +73,6 @@
buildActionMask = 2147483647;
files = (
ED297163215061F000B7C4FE /* JavaScriptCore.framework in Frameworks */,
840D44FCCBB14F97B77D9443 /* libz.tbd in Frameworks */,
C091D09FD11FDDB8E939257D /* libPods-ZulipMobile.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -123,7 +120,6 @@
children = (
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
ED2971642150620600B7C4FE /* JavaScriptCore.framework */,
B2BC2F95A8684C44BAFA7B11 /* libz.tbd */,
74F3CD22CB932FA7EEE0BB66 /* libPods-ZulipMobile.a */,
338F4382FA4C3F52F95A1F5B /* libPods-ZulipMobileTests.a */,
);
Expand Down
13 changes: 13 additions & 0 deletions react-native.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,18 @@ module.exports = {
android: null,
},
},
'react-native-screens': {
platforms: {
// We haven't enabled `react-native-screens` yet, that's
// #4111. See 250cde501.
ios: null,
},
},
'react-native-document-picker': {
platforms: {
// iOS file uploads aren't supported yet. see 250cde501.
ios: null,
},
},
},
};
15 changes: 14 additions & 1 deletion tools/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@ EOF
exit 1
fi

pod install --project-directory="$ROOT_DIR/ios"
# We can't go back to `pod install --project-directory=ios` (thus
# avoiding state-changing `cd` commands) until RN v0.62.0, when we
# get the resolution of
# https://github.com/react-native-community/cli/issues/657.
#
# @react-native-community/cli@5724d29dc was released in v3.0.0-alpha.3
# facebook/react-native@e523302fb was released in v0.62.0-rc.0
#
# We tried the workaround at that issue (passing a "." argument to
# `use_native_modules`) and got other errors that were not
# covered. So, we have to `cd` twice.
cd "$ROOT_DIR/ios"
pod install
cd "$ROOT_DIR"
}

jetify() {
Expand Down

0 comments on commit c25981b

Please sign in to comment.