-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Guide to creating a New Architecture app from template #3056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cipolleschi
merged 28 commits into
facebook:feat/new-architecture-guide-refactoring
from
lindboe:use-new-template
Apr 20, 2022
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
06a3766
Start new template guide
lindboe f6aff0d
Update title
lindboe e7446f2
Use tabs for target OS
lindboe be2eb18
Capitalize New Architecture, simplify
lindboe 8754e60
Preliminary section for Hermes
lindboe a93abdd
Reword to emphasize importance of Hermes usage
lindboe 5e9a0d9
Show new arch in use
lindboe a1463d8
Add build speed article link
lindboe 77dd04d
Add pro tip for pod install alias
lindboe 7e0ccf0
Restructure, repeat less
lindboe e98f1b1
Note about Expo
lindboe 86a434c
Include command on uninstalling global CLI
lindboe 3854b96
How to learn more
lindboe 2105e4f
Remove headers in tabs
lindboe ea370fb
Make header more clear
lindboe eaa0ee2
Use quote block less often
lindboe 7ea7ef0
Opt for instructions using XCode
lindboe 02a9b4e
Fix lint issue
lindboe f845267
Improve wording
lindboe c0a3d43
Use product name
lindboe d5bc865
Fix line wraps
lindboe eea036b
Reword based on feedback
lindboe f5e1324
Note use of bundle install
lindboe aada4dc
Pod removal instructions
lindboe df4c17e
Convert quotes to admonitions
lindboe 9e06f9d
Convert Note: to admonitions
lindboe cbb01bc
Feedback: Change admonitions to caution
lindboe 1ea529b
PR feedback
lindboe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| > If you previously installed a global `react-native-cli` package, please remove it as it may cause unexpected issues: | ||
| > | ||
| > ```shell | ||
| > npm uninstall -g react-native-cli @react-native-community/cli | ||
| > ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,130 @@ | ||
| --- | ||
| id: use-app-template | ||
| title: Using the New App Template | ||
| title: Creating a New Architecture App | ||
| --- | ||
|
|
||
| This section describes the new app template generated by the React Native CLI and how to use it properly. | ||
| It should explain how to create a new app, which command should be issued to install the dependencies and to run it on the different platforms. | ||
| import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants'; | ||
|
|
||
| import RemoveGlobalCLI from '.././\_remove-global-cli.md'; | ||
|
|
||
| This page will help you create a new React Native app that uses the New Architecture. | ||
|
|
||
| ## Development environment | ||
|
|
||
| Before continuing, make sure you've followed all the steps in [Setting up the development environment](getting-started.md), under the **React Native CLI Quickstart** tab. | ||
|
|
||
| If following the setup guide, stop when you reach the section **Running your React Native Application**, and resume following this guide. | ||
|
|
||
| :::caution | ||
| If you're using Expo, you can't enable the New Architecture at the moment, and will have to wait for a future release of the Expo SDK. | ||
| ::: | ||
|
|
||
| ## Creating a new application | ||
|
|
||
| <RemoveGlobalCLI /> | ||
|
|
||
| If you already have your development environment set up, create a new React Native project from the template: | ||
|
|
||
| ```shell | ||
| npx react-native init AwesomeProject | ||
lindboe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| :::caution | ||
| The New Architecture is available in React Native version 0.68 or later. | ||
| ::: | ||
|
|
||
| ## Configuration | ||
|
|
||
| Follow the steps below to enable the New Architecture and build the app. | ||
|
|
||
| ### Enable Hermes | ||
|
|
||
| Hermes is an open-source JavaScript engine optimized for React Native. [Hermes will be the default engine in the future](https://github.com/reactwg/react-native-new-architecture/discussions/4), and we highly recommend you use it. | ||
|
|
||
| Please [follow the instructions on the React Native website](hermes.md) in order to enable Hermes in your application. | ||
|
|
||
| ### Enable the New Architecture | ||
|
|
||
| #### Target OS | ||
|
|
||
| <Tabs groupId="platform" defaultValue={constants.defaultPlatform} values={constants.platforms} className="pill-tabs"> | ||
| <TabItem value="ios"> | ||
|
|
||
| Navigate to the `ios` directory and run the following: | ||
|
|
||
| ```shell | ||
| # from `ios` directory | ||
| bundle install && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install | ||
| ``` | ||
|
|
||
| Then build and run the app as usual: | ||
|
|
||
| ```shell | ||
| yarn ios | ||
| ``` | ||
|
|
||
| :::note | ||
| You will need to run `pod install` each time a dependency with native code changes. Make this command easier to run by adding it to `scripts` to your project's `package.json` file: | ||
|
|
||
| ``` | ||
| "scripts": { | ||
| "pod-install": "RCT_NEW_ARCH_ENABLED=1 bundle exec pod install" | ||
| } | ||
| ``` | ||
|
|
||
| and run it with `yarn pod-install`. Note that `bundle install` does not need to run a second time, as long as the Gemfile has not changed. | ||
| ::: | ||
|
|
||
| #### Troubleshooting | ||
|
|
||
| ##### `react-native run-ios` fails | ||
|
|
||
| If you see a build failure from `react-native run-ios`, there may be cached files from a previous build with the old architecture. Clean the build cache and try again: | ||
|
|
||
| 1. Open the project `ios/project.xcworkspace` in Xcode | ||
| 2. In XCode, choose Product > Clean Build Folder | ||
| 3. In the project directory, remove the `ios/Podfile.lock` file and `ios/Pods` directory: `rm -rf ios/Podfile.lock ios/Pods` | ||
| 4. Re-run `yarn pod-install` and `yarn ios` | ||
|
|
||
cipolleschi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </TabItem> | ||
| <TabItem value="android"> | ||
|
|
||
| Set the `newArchEnabled` property to `true` by **either**: | ||
|
|
||
| - Changing the corresponding line in `android/gradle.properties` | ||
| - Setting the environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true` | ||
|
|
||
| Then build and run the app as usual: | ||
lindboe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```shell | ||
| yarn android | ||
| ``` | ||
|
|
||
| :::note | ||
| You may notice longer build times with the New Architecture, due to additional step of C++ compilation with the Android NDK. To improve your build time, see [Speeding Up Your Build Phase](docs/build-speed.md). | ||
| ::: | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ### Confirming the New Architecture is in use | ||
|
|
||
| After you build and run the app, when Metro serves the JavaScript bundle, you should see `"fabric": true` in the Metro logs: | ||
|
|
||
| <img src="/docs/assets/metro-new-arch.png" alt="Metro shows fabric: true" width="600" /> | ||
|
|
||
| ### Want to know more? | ||
cipolleschi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| If you'd like to view the code changes relevant for the New Architecture, take a look at the [upgrade helper from version 0.67.4 to 0.68.0](https://react-native-community.github.io/upgrade-helper/?from=0.67.4&to=0.68.0). Files that were added for the New Architecture are marked with a yellow banner. | ||
|
|
||
| For further explanations of what each file is doing, check out these guides to walk through the changes step-by-step: | ||
|
|
||
| #### Android | ||
|
|
||
| - [Enabling TurboModules on Android](new-architecture-app-modules-android.md) | ||
lindboe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - [Enabling Fabric on Android](new-architecture-app-renderer-android.md) | ||
|
|
||
| #### iOS | ||
|
|
||
| - [Enabling TurboModules on iOS](new-architecture-app-modules-ios.md) | ||
| - [Enabling Fabric on iOS](new-architecture-app-renderer-ios.md) | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.