Due to business needs, I started learning RN in preparation for future requirements. Although I had used RN before, the project setup was done using a pre-packaged scaffold, so I didn't have a deep understanding of it. Therefore, I plan to document my personal process of setting up an RN project from scratch, while also collecting some resources.
Suitable for: Those with a front-end background, who have a basic front-end development environment, and want to understand the process of setting up an RN project with Expo.
RN Related Resources#
- Official website: Site Unreachable
- Chinese website: Introduction · React Native Chinese Website
- Expo official website: Expo
- GitHub resources
- GitHub - jondot/awesome-react-native Awesome React Native is a great style list that curates the best React Native libraries, tools, tutorials, articles, etc.
- GitHub - infinitered/ignite Ignite is the most popular React Native application template for Expo and bare React Native, the culmination of over six years of continuous React Native development.
- Blog post
Development Environment#
Setting up Android Development Environment on Windows#
- Setting up the development environment · React Native
- Setting up the development environment · React Native Chinese Website
On Android, it's important to install Android Studio & Android SDK. Android Studio will by default install the latest version of the Android SDK. Currently, the SDK version required to compile React Native applications is Android 13 (Tiramisu)
(note that the SDK version is not the same as the terminal system version; RN currently supports devices running Android 5 and above). You can choose to install various versions of the SDK in the SDK Manager of Android Studio.
1. Install Android Studio#
Download and install Android Studio Download and install Android Studio. In the Android Studio installation wizard, make sure to check the boxes next to the following items:
Android SDK
Android SDK Platform
Android Virtual Device
- If you haven't used Hyper-V:
Performance (Intel ® HAXM)
(for AMD or Hyper-V, please see here)
2. Install Android SDK#
Android Studio will install the latest Android SDK by default. Building React Native applications with native code especially requires the Android 13 (Tiramisu)
SDK. You can install other Android SDKs through the SDK Manager in Android Studio.
- Open Android Studio, click the "More Actions" button, and select "SDK Manager".
- In the SDK Manager, select the "SDK Platforms" tab, and check the box next to "Show Package Details" in the lower right corner. Look for and expand the
Android 13 (Tiramisu)
entry, and ensure the following items are checked:
Android SDK Platform 33
Intel x86 Atom_64 System Image
orGoogle APIs Intel x86 Atom System Image
3. Next, select the "SDK Tools" tab and check the box next to "Show Package Details". Look for and expand the Android SDK Build-Tools
entry, and ensure that 33.0.0
is selected (ps: now it is 34.0.0
).
- Configure the
ANDROID_HOME
environment variable
Advanced system settings - Environment Variables - Click New... to create a newANDROID_HOME
user variable pointing to the path of your Android SDK:
By default, the SDK is installed in the following location:
%LOCALAPPDATA%\Android\Sdk
e.g., C:\Users\xxxx\AppData\Local\Android\Sdk
You can find the actual location of the SDK in Android Studio settings under Appearance & Behavior → System Settings → Android SDK.
Verify that the environment variable has been added:
- Open PowerShell
- Copy and paste
Get-ChildItem -Path Env:\
into PowerShell - Verify that
ANDROID_HOME
has been added
Using Expo#
Why use Expo?#
Expo is a set of tools, libraries, and services that allows you to build native iOS and Android applications by writing JavaScript. In simpler terms, it adds an additional layer on top of React Native, making our development easier and faster.
- Those who have worked on mobile before will definitely worry about various native features (camera, photo album, location, Bluetooth, etc.) before doing cross-platform development. Using Expo will be much faster than developing a bare React Native app, and it will help you avoid many pitfalls.
- For front-end developers who have not worked on mobile, this is even more necessary; otherwise, some hidden limitations and pitfalls of mobile development can be quite troublesome.
——React Native Development Based on Expo (I) Project Setup - Juejin
Next, we will set up an Expo application based on the official tutorial: Create your first app - Expo Documentation
Initialize Expo Project#
Use create-expo-app
to initialize a new Expo application. It is a command-line tool that allows you to create a new React Native project with the expo
package installed.
npx create-expo-app StickerSmash
cd StickerSmash
Download the images and other static resources needed for the demo project from the official documentation and replace the assets in the project: Download assets
Now, let's open the project directory in our favorite code editor or IDE. In this tutorial, we will use VS Code as an example.
Start the Project#
To run the project on the web, we need to install the following dependencies that help run the project on the web:
npx expo install react-dom react-native-web @expo/webpack-config
Start
npx expo start
Scan QR code | Successful Start |
---|---|
Recommended Libraries for Expo#
Here are some libraries officially recommended to work with Expo:
- Safe area library react-native-safe-area-context
react-native-safe-area-context
provides a flexible API for accessing device safe area inset information on Android and iOS. It also offers a SafeAreaView component that you can use instead of View to automatically consider the safe area when inserting views.
- Animation library react-native-reanimated
- In your Expo project, you can use React Native's animation API. However, if you want to use more advanced animations with better performance, you can use the
react-native-reanimated
library. It provides an API that simplifies the process of creating smooth, powerful, and maintainable animations.
- In your Expo project, you can use React Native's animation API. However, if you want to use more advanced animations with better performance, you can use the
- Storing data Store data - Expo Documentation
expo-secure-store
provides a way to securely store key-value pairs locally on the device with encryption.
There are other recommended libraries, which you can see here:
Getting Started with React Native and Expo SDK - Juejin
- AppAuth, AuthSession: Authenticate users via OAuth
- SplashScreen: Create a splash screen when launching the application (official documentation)
- localization Manage your application's l10n/i18n for localization purposes
- AppLoading: Load assets, fonts, etc.
- MapView: Use maps in your application
- ImagePicker or ImageManipulator: Open images or videos from the device
- Sharing: Share data between applications and devices
- SecureStore: Save data on the device's storage
- Camera: Take photos and videos using the device's camera
- Notifications: Push notifications from Expo push services