Skip to content

Commit 4120eff

Browse files
committed
added documentation
1 parent 5e19777 commit 4120eff

2 files changed

Lines changed: 106 additions & 1 deletion

File tree

CONTRIBUTING-NIX.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# React Native Development Nix Environment Setup
2+
3+
This document outlines how to set up your React Native development environment using Nix flakes for reproducibility and isolation.
4+
5+
## Disclaimer
6+
7+
This was tested on an Arch Linux system with AMD CPU and GPU. There are likely problems with NVIDIA GPUs.
8+
9+
Compatibility with Microsoft WSL2 is not guaranteed, but should work withoud major issues, except for the emulator.
10+
11+
## Prerequisites
12+
13+
* **Nix installed**: [https://nixos.org/download.html](https://nixos.org/download.html)
14+
* **Git**: Required for cloning the repository.
15+
* **KVM (for emulator, if enabled)**: Ensure KVM is enabled and your user is in the `kvm` group for optimal emulator performance:
16+
```bash
17+
sudo usermod -aG kvm $USER && newgrp kvm # (or log out/in)
18+
kvm-ok # Verify KVM acceleration
19+
```
20+
* **GPU Drivers (for emulator, if enabled)**: For hardware-accelerated emulator (AMD/Intel), ensure host Vulkan drivers are working:
21+
```bash
22+
vulkaninfo | grep -i "device name" # Should show your GPU
23+
```
24+
If not, install `vulkan-radeon` (AMD) or `vulkan-intel` (Intel) on your host system and reboot.
25+
26+
27+
## Getting Started
28+
29+
1. **Clone the Project:**
30+
```bash
31+
git clone <your-fork-url>
32+
cd <your-fork-name>
33+
```
34+
35+
2. **Enter the Development Shell:**
36+
37+
If you have `npm` or `yarn` installed, use the defined scripts:
38+
* **For Physical Device Only (default):**
39+
```bash
40+
npm run nix # or yarn nix
41+
```
42+
* **For Emulator Development (explicitly enable):**
43+
```bash
44+
npm run nix-emulator # or yarn nix-emulator
45+
```
46+
47+
If you do not have `npm`/`yarn` installed, execute the commands manually:
48+
* **For Physical Device Only (default):**
49+
```bash
50+
nix develop --extra-experimental-features nix-command --extra-experimental-features flakes
51+
```
52+
* **For Emulator Development (explicitly enable):**
53+
```
54+
nix develop .#emulator --extra-experimental-features nix-command --extra-experimental-features flakes
55+
```
56+
57+
The first time, this will download and set up all required tools, which can take considerable time. Subsequent entries will be much faster. You will also see a message about "Setting up writable Android SDK..." which only happens once.
58+
59+
## Development Workflow
60+
61+
Once inside the `nix develop` shell, all tools are available.
62+
63+
### 1. Start Metro Bundler
64+
65+
Open a new terminal or run in the background:
66+
```bash
67+
npm start
68+
```
69+
70+
### 2. Physical Device Development
71+
72+
1. **Connect Device**: Enable USB debugging on your Android device and connect it via USB.
73+
2. **Verify Device**:
74+
```bash
75+
adb devices
76+
```
77+
3. **Mirror Screen (Optional)**:
78+
```bash
79+
scrcpy # Mirrors screen, provides control
80+
scrcpy -s <device_serial> # If multiple devices connected
81+
```
82+
4. **Run App**:
83+
```bash
84+
npx run android
85+
```
86+
87+
### 3. Android Emulator Development (if enabled)
88+
89+
1. **Launch Emulator**:
90+
```bash
91+
emulator -avd ReactNative_API35 -gpu host -no-metrics -no-audio
92+
```
93+
* Use `-gpu swiftshader_indirect` if hardware acceleration (`-gpu host`) fails.
94+
95+
2. **Verify Emulator**:
96+
```bash
97+
adb devices
98+
```
99+
3. **Run App**:
100+
Launches the the emulater automatically, if it is not already running.
101+
```bash
102+
npx run android
103+
```

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"open": "open ./android/app/build/outputs/apk/release/",
1515
"strings": "node scripts/stringTypes.cjs",
1616
"prepare": "husky install",
17-
"rebuild": "rm -rf node_modules/ ./android/build/ ./android/app/build/ ./android/app/.cxx && npm i && cd android/ && ./gradlew clean && cd .. && npm start -- --reset-cache"
17+
"rebuild": "rm -rf node_modules/ ./android/build/ ./android/app/build/ ./android/app/.cxx && npm i && cd android/ && ./gradlew clean && cd .. && npm start -- --reset-cache",
18+
"nix": "nix develop --extra-experimental-features nix-command --extra-experimental-features flakes",
19+
"nix-emulator": "nix develop .#emulator --extra-experimental-features nix-command --extra-experimental-features flakes"
1820
},
1921
"codegenConfig": {
2022
"name": "LNReaderSpec",

0 commit comments

Comments
 (0)