question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React-native link only links to 1st Xcode target

See original GitHub issue

Environment

React Native Environment Info: System: OS: macOS High Sierra 10.13.6 CPU: x64 Intel® Core™ i7-4870HQ CPU @ 2.50GHz Memory: 53.57 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 8.9.1 - ~/.nvm/versions/node/v8.9.1/bin/node Yarn: 1.3.2 - ~/.nvm/versions/node/v8.9.1/bin/yarn npm: 5.5.1 - ~/.nvm/versions/node/v8.9.1/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0 Android SDK: Build Tools: 19.1.0, 20.0.0, 21.1.2, 22.0.1, 23.0.1, 23.0.2, 23.0.3, 24.0.0, 24.0.1, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.0, 28.0.1 API Levels: 22, 23, 24, 25, 26, 27, 28 IDEs: Android Studio: 3.1 AI-173.4819257 Xcode: 10.0/10A255 - /usr/bin/xcodebuild npmPackages: @types/react: ^16.4.14 => 16.4.18 @types/react-native: ^0.57.6 => 0.57.6 react: 16.6.0-alpha.8af6728 => 16.6.0-alpha.8af6728 react-native: 0.57.3 => 0.57.3 npmGlobalPackages: create-react-native-app: 2.0.2 react-native-cli: 2.0.1 react-native: 0.50.3

Description

If you have multiple targets in Xcode, and try to link a new dependency with react-native link, it will only link for the first Xcode target.

This is a problem for us as I can already see the bugs being opened where one of the builds we distribute has bugs because of an unlinked dependency in the target.

The desired behaviour would be either one (or both) of the following:

  • react-native link will link all targets by default
  • allow a --target="" flag for react-native link, so that each target can be linked via the cli

Reproducible Demo

  1. Create an ejected RN project
  2. Add a second target in Xcode
  3. Install a new project dependency and then run react-native link to link that dependency
  4. Look at the Linked Frameworks & Libraries in Xcode under both targets. The new library will only be listed under your first target.

Note, this was opened in the past and has been auto-closed several times. https://github.com/facebook/react-native/issues/18503 https://github.com/facebook/react-native/issues/17381

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
bartolkaruzacommented, Nov 8, 2018

I would just like to add a way to deal with library dependencies in Xcode that I use for every project that has more than 1 target.

Instead of duplicating the dependencies to each target, I create a single Cocoa Touch Library target (named base), to which I add all dependencies. Then that base target is added as a dependency to all other targets. It is a more DRY approach to dependencies in Xcode and works well with react-native link if you make sure the base target is the first one in the list.

Add this: screen shot 2018-11-07 at 10 43 41

Make sure it’s at the top: screen shot 2018-11-07 at 10 44 19

This target has your deps: screen shot 2018-11-07 at 10 49 33

Your targets just have this list of deps: screen shot 2018-11-07 at 10 44 29

Hope the base library approach helps you find that convenience back 😃

This approach would not work if we change the behaviour of react-native link to add it to each target. So I think it may be hard to foresee the impact of your proposed change on all the various Xcode project setups out there. People do things in different ways and assuming each target should have each dependency linked is dangerous.

2reactions
dev6jamescommented, Nov 6, 2018

Is having more than 1 target really an “expert Xcode setup”. Are we saying that React Native should only provide abstractions for the most simple projects and anything more than that means go native and lose a ton of convenience? What is the downside to having a more powerful cli?

@bartolkaruza I would like to contribute although I was hoping that if was not too arduous a change that it’d be a lot faster and easier for an existing contributor. If it’s came up several times then there is demand out there and my goal was to reinforce that demand. I may look into it if needs must though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Linking Libraries - React Native
React Native will link your libs based on dependencies and devDependencies in your package. json file. That's it!
Read more >
Deep Linking in React Native with Universal Links and URL ...
The first step is to define the scheme name itself; this is done in Xcode. With your project selected within the Project Navigator,...
Read more >
What is react-native link? - Stack Overflow
react -native link is an automatic way for installing native dependencies. It is an alternative to manually linking the dependency in your ...
Read more >
Understanding deep linking in React Native - LogRocket Blog
A comprehensive guide to deep linking in React Native for iOS 14+ and Android 11.x, including a step-by-step tutorial.
Read more >
How to set up react native universal links for iOS - Ekreative
1. Upload an apple-app-site-association file to your web server · 2. Preparing the app for universal linking · 3. Setting up universal links...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found