React Native Mac Settings
๋ชฉ์ฐจ
๐น Version
๐ ์ค์น ํ์ผ
ํ์ผ๋ช | Homebrew | node | ruby | yarn | Xcode | Android Studio | watchman |
Version | 3.6.6 | 16.15.1 | 2.7.5 | 1.22.19 | 14.0.1 | 2021.3.1 Patch | - |
๐ ๊ธฐ์ ์คํ
๊ธฐ์ ์คํ๋ช | React-Native | TypeScript | react-navigation/native |
Version | 0.70 | 4.8.3 | 6.0.13 |
๐ Environment Settings
โ๏ธ ๊ณตํต
1. homebrew ์ค์น
- ๊ณต์๋ฌธ์ ์ฐธ๊ณ ํ๊ธฐ ๋๋ ๋ธ๋ก๊ทธ์์ 2๋ฒ homebrew ์ค์นํ๊ธฐ ์ฐธ๊ณ
- https://conqueror-g.tistory.com/m/70
- ์ค์นํ์ธ
brew -v
2. node.js ์ค์น
- ํ๋จ์ ์ฝ๋๋ฅผ ์ ๋ ฅํ๊ณ Enter๋ฅผ ๋๋ฅธ๋ค.
- ์ฃผ์์ฌํญ : homebrew๊ฐ ์ค์น๋์ด์์ด์ผ ํ๋ค.
brew install node
- ์ค์น ํ์ธ
node -v
3. watchman ์ค์น
- ํ๋จ์ ์ฝ๋๋ฅผ ์ ๋ ฅํ๊ณ Enter๋ฅผ ๋๋ฅธ๋ค.
- ์ฃผ์์ฌํญ : homebrew๊ฐ ์ค์น๋์ด์์ด์ผ ํ๋ค.
brew install watchman
- ์ค์น ํ์ธ
watchman -v
4. yarn ์ค์น
- ํ๋จ์ ์ฝ๋๋ฅผ ์ ๋ ฅํ๊ณ Enter๋ฅผ ๋๋ฅธ๋ค.
- ์ฃผ์์ฌํญ : homebrew๊ฐ ์ค์น๋์ด์์ด์ผ ํ๋ค.
brew install yarn --ignore-dependencies
- ์ค์น ํ์ธ
yarn -v
5. react-native ์ค์น
npm install -g react-native
โ๏ธ IOS
๐ Xcode
1. ์ํ ๊ฐ๋ฐ์ ํํ์ด์ง์์ ์ค์น
-- Apple ID๋ก ๋ก๊ทธ์ธํ๊ธฐ
-- ์๋จ ํญ์ Applications ํญ ํด๋ฆญ
-- ์์ถ ํ์ผ ๋ค์ด ๋ฐ๊ธฐ (์ธํฐ๋ท ๋ค์ด์๋์ ๋ฐ๋ผ ๋ค๋ฅด์ง๋ง 5~10๋ถ ์์)
2. ์์ถ ํด์ (5~10๋ถ ์์)
3. Xcode ์คํ
- ์ฃผ์์ฌํญ : ๋งฅ OS 12.5 ์ด์์ด์ด์ผ ์คํ ํ ์ ์์ต๋๋ค. ์คํ์ด ์๋๋ค๋ฉด OS๋ฅผ ์ ๋ฐ์ดํธ ํฉ์๋ค.
4. Xcode and Apple SDKs Agreement
- Agree ํด๋ฆญ
- ๋งฅ ๊ณ์ ์ํธ ์ ๋ ฅ
- ์ด๋ค ํ๋ซํผ์ ์ค์นํ ์ง check
-- ์๋ฌด๊ฒ๋ ์ฒดํฌํ์ง ์๊ณ install
- Xcode ์คํํ๋ฉด ๋์ค๋ ํ๋ฉด์์
-- ๋งฅ OS ์๋จ ํญ์์ Xcode ํด๋ฆญ
--- Preferences.. ํด๋ฆญ
--- Locations Tab ํด๋ฆญ
--- Command Line Tools์์ ๊ณต๋ฐฑ์นธ ํด๋ฆญํ๋ฉด ๋ฒ์ ์ด ํ์๋จ
--- ๊ณ์ ์ํธ ์ ๋ ฅ
--- ์ ํ ์๋ฃ
๐ Cocoapods
1. ํฐ๋ฏธ๋์์ ์ค์น
- ํ๋จ์ ์ฝ๋๋ฅผ ์ ๋ ฅํ๊ณ Enter๋ฅผ ๋๋ฅธ๋ค.
-- ๊ฒฝ๋ก : ~
sudo gem install cocoapods
-- ๊ณ์ ์ํธ ์ ๋ ฅ
2. ์ ์ค์น๋์๋์ง ํ์ธ
- ํ๋จ์ ์ฝ๋๋ฅผ ์ ๋ ฅํ๊ณ Enter๋ฅผ ๋๋ฅธ๋ค.
pod --version
- ํ๋จ์ ์ฌ์ง์ฒ๋ผ ๋์ค๋ฉด ์๋ฃ
โ๏ธ Android
๐ JAVA Development Kit
1. homebrew/case-versions ์ถ๊ฐํ๊ธฐ
- ํ๋จ์ ์ฝ๋๋ฅผ ์ ๋ ฅํ๊ณ Enter๋ฅผ ๋๋ฅธ๋ค.
-- ๊ฒฝ๋ก : ~
--- ์ฃผ์์ฌํญ : homebrew๊ฐ ์ค์น๋์ด์์ด์ผ ํ๋ค.
brew tap homebrew/cask-versions
brew install --cask zulu11
--- ์ฃผ์์ฌํญ : ๊ณต์ ๋ฌธ์์์ ์ค์นํด์ผํ๋ ์ฝ๋๊ฐ ๋ฐ๋์ง๋ ์์๋์ง ์ฒดํฌํด์ฃผ์ธ์
--- https://reactnative.dev/docs/environment-setup
๐ ์๋๋ก์ด๋ ์คํ๋์ค
1. ๊ณต์๋ฌธ์๋ก ์ด๋ํด์ ์ง์ ์ค์น
-- Download Android Studio ํด๋ฆญ
-- Checkbox ํด๋ฆญ ๋ฐ ์์ ์ ๋ ธํธ๋ถ ๊ธฐ์ข ์ ๋ฐ๋ผ intel or Apple ์ ํํด์ ํด๋ฆญํ๊ธฐ
-- dmgํ์ผ ๋ค์ด๋ก๋๊ฐ ๋๋๋ฉด ์ด๊ธฐ
-- ์ ํ๋ฆฌ์ผ์ด์ ๋ฑ๋กํ๊ธฐ
2. ์ฑ ์คํํ๊ธฐ
3. Do not import ์ ํํ๊ณ OK ๋ฒํผ ํด๋ฆญ
4. Welcome
- Don’t send ํด๋ฆญ
5. Welcome
- Next ํด๋ฆญ
6. Install Type
- Custom์ ์ฒดํฌํ๊ณ Next ๋ฒํผ ํด๋ฆญ
7. Select default JDK Location
- Next ํด๋ฆญ
8. Select UI Theme
- ํ ๋ง ์์ ์ ํํ์ฌ ํด๋ฆญ
- Next ํด๋ฆญ
9. SDK Components Setup
- Next ํด๋ฆญ
10. Verify Settings
- Next ํด๋ฆญ
11. License Agreement
- Licenses ๋ชฉ๋ก์ ํด๋ฆญํ์ฌ ๋ชจ๋ Accept
- Finish
12. Download
- ๋ค์ด๋ก๋๊ฐ ์๋ฃ๋๋ฉด Finish
13. ์ฑ์ด ์ฌ์คํ๋จ ( Welcome to Android Studio )
- More Actions
-- SDK Manager
14. preferences
- SDK Platforms
-- ํ๋จ ์ฒดํฌ๋ฐ์ค์ ‘Show Package Details’ ์ฒดํฌ
-- Android Tiramisu๋ฅผ ์ฒดํฌ ํด์ ํ์ง ์๋๋ค.
--- ์ฃผ์์ฌํญ : ์ฒดํฌ๋ฅผ ํด์ ํ๋ฉด ์๋ฎฌ๋ ์ดํฐ๊ฐ ์คํ๋์ง ์๋๋ค.
-- ๋ ๋ถ๋ฅ Android 12.0 (s) ํญ๋ชฉ ์ฐพ๊ธฐ
--- ์ฃผ์์ฌํญ: ํ๋ซํผ์ ๊ณต์๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ธ์.
--- https://reactnative.dev/docs/environment-setup
---- ์ค ๋ถ๋ฅ
----- Android SDK paltform 31 ์ฒดํฌ
----- Google APIs Intel x86 Atom System Image or Intel x86 Atom_64 System Image or Google APIs ARM 64v8a System Image ์ฒดํฌ
- SDK Tools
-- ์ฃผ์์ฌํญ: ํ๋ซํผ์ ๊ณต์๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ธ์.
--- https://reactnative.dev/docs/environment-setup
-- ํ๋จ ์ฒดํฌ๋ฐ์ค์ ‘Show Package Details’ ์ฒดํฌ
--- 33.0.0 ์ฒดํฌ
--- 31.0.0 ์ฒดํฌ
--- 30.0.3 ์ฒดํฌ
--- Apply ํด๋ฆญ
15. Confirm Change ์๋ฆผ์ฐฝ ๋์ค๋ฉด OK ํด๋ฆญ
16. SDK Component Installer
- ์ค์น๊ฐ ์๋ฃ๋๋ฉด Finish ํด๋ฆญ
17. OK
18. ์ค์นํ ํ๋ซํผ์ ๋ง๊ฒ ์๋ฎฌ๋ ์ดํฐ ์ค์ ํ๊ธฐ
- more Actions ํด๋ฆญ
- Virtual Device Manager ํด๋ฆญ
- ๊ธฐ์กด์ ๊ฒ ์ญ์
-- … ํด๋ฆญ
-- Delete ํด๋ฆญ
- ๋ค์ ํ๋ฒ ๋ฌผ์ด๋ณด๋ฉด Yes ํด๋ฆญ
- Create Device ํด๋ฆญ
- ์ด์ ์ SDK Manager์์ ์ค์นํ Android 12.0 s์ ๋ง๋ ๊ธฐ์ข ์ ํ
-- ์ ํ ํ๋ค๋ฉด, Next ๋ฒํผ ํด๋ฆญ
- Recommened์์ Android12์ ํด๋นํ๋ ๊ฒ์ ์ค์น
-- ์์ ๋ค์ด๋ก๋ ์์ด์ฝ์ด ์๋ค๋ฉด ์ค์น, ์๋ค๋ฉด ๋ค์์ผ๋ก ์งํ
- x86 Image ํญ ํด๋ฆญ
-- ์์ ๋ค์ด๋ก๋ ์์ด์ฝ์ด ํ์๋๋ ๊ฒ์ค 12.0๋ง ์ค์นํ๋ค.
-- ์์ด์ฝ์ ํด๋ฆญํ๋ฉด ์ค์น ์์
- ์ค์น๊ฐ ๋๋๋ฉด ํด๋น ๊ธฐ์ข ์ ํํ๊ณ Next ๋ฒํผ ํด๋ฆญ
- Finish ๋ฒํผ ํด๋ฆญ
19. ์๋๋ก์ด๋ ์คํ๋์ค ํ๊ฒฝ ๋ณ์ ์ค์
- ํฐ๋ฏธ๋ ์คํํ๊ธฐ
- ๋ฃจํธ ๊ฒฝ๋ก ํ์ธ
-- ๊ฒฝ๋ก : ~
- ~/.zshrc ํ์ผ ์ด๊ธฐ
-- ํ๋จ์ ์ฝ๋๋ฅผ ์ ๋ ฅํ๊ณ Enter๋ฅผ ๋๋ฅธ๋ค.
--- ์ฃผ์์ฌํญ : zsh๊ฐ ์ค์น๋์ด์์ง ์๋ค๋ฉด ~/.bash_profile๋ก ์ด๋
code ~/.zshrc
or
code ~/.bash_profile
- ์ ์ผ ํ๋จ์์ ๋ฐ์ ๋์ด๋ ์ฝ๋ ์ถ๊ฐํ๊ธฐ
# export ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
-- ์์ ์ ์๋๋ก์ด๋ SDK ์์น๋ SDK Manager์์ ํ์ธํ ์ ์๋ค.
--- ์๋๋ก์ด๋ ์คํ๋์ค์์ SDK Manager๋ฅผ ๋ค์ ์คํ
--- ์๋จ์ ๋ณด๋ฉด Android SDK Location์ ๊ฒฝ๋ก ํ์๋๋ค. Edit์ ๋๋ฅธ๋ค.
--- ๊ฒฝ๋ก๋ฅผ ๋ณต์ฌํ๋ค.
--- ์๋ํฐ๋ก ๋์๊ฐ์ ๊ฒฝ๋ก๋ฅผ ์์ ํ๋ค.
---- ์ฃผ์์ฌํญ : ๋ณต์ฌํด์จ ๊ฒฝ๋ก ๋ค์ /Android/sdk๋ฅผ ๋ ๋ถ์ด์ง ์๋๋ก ํ๋ค
- ์ ์ฅํ๊ณ ์๋ํฐ๋ฅผ ์ข ๋ฃํ๋ค.
-- command + s ๋ฅผ ๋๋ฅด๋ฉด ์ ์ฅ๋๋ค.
- ํฐ๋ฏธ๋๋ก ๋์๊ฐ๋ค.
- ์์ฑํ ๋ด์ฉ ์ ์ฉํ๊ธฐ
-- ํ๋จ์ ์ฝ๋๋ฅผ ์ ๋ ฅํ๊ณ Enter๋ฅผ ๋๋ฅธ๋ค.
source ~/.zshrc
or
source ~/.bash_profile
- ์ ๋์๋์ง ํ์ธํ๊ธฐ
-- ํ๋จ์ ์ฝ๋๋ฅผ ์ ๋ ฅํ๊ณ Enter๋ฅผ ๋๋ฅธ๋ค.
adb
--- ํ๋จ ์ฒ๋ผ ๋์ค๋ฉด ์๋ฃ
--- ๋ง์ฝ ํ๋จ๊ณผ ๊ฐ์ด ๋์ค์ง ์๋๋ค๋ฉด, 3๊ฐ์ง๋ฅผ ์ฒดํฌ ํ๋ค.
1. code ~/.zshrc ์์ ๊ฒฝ๋ก๋ฅผ ์๋ชป ์ค์ ํ์ง๋ ์์๋์ง ?
2. ์ ์ฅ ์ํ๊ณ source ~/.zshrc ๋ฅผ ์คํํ์ง๋ ์์๋์ง ?
3. source ~/.zshrc ๋ฅผ ์คํ ์ํ์ง ์์๋์ง ?
Android Debug Bridge verstion 1.0.41
Version 33.0.3-8952118
Installed as /์์ ์ ์๋๋ก์ด๋SDK ์์น/platform-tools/adb
๐ Create React-Native
โ๏ธ React_Native + TypeScript ( ํ์ )
๐ ์ค์น
npx react-native init MyApp --version 0.70 --template react-native-template-typescript
- ๋ง์ฝ cli.function error๋ก ์ฑ ์์ฑ์ ์คํจํ๋ค๋ฉด ์ด๊ฑธ ๋ฐ๋ผํด๋ณด์ธ์
npm uninstall -g react-native-cli or yarn global remove react-native-cli
- ๋ง์ฝ ruby version์ด ์๋ง์์ CocaoPods install์ ์คํจํ๋ค๋ฉด ์ด๊ฑธ ๋ฐ๋ผํด๋ณด์ธ์
-- https://conqueror-g.tistory.com/280
๐ ์คํ
- ์ฃผ์์ฌํญ : ๋น๋ 1~3๋ถ ์์
-- ์๋์์ ์ธํ ํ์ง ์๊ณ ๋จผ์ ๋น๋ ๋๋์ง ํ์ธํ๊ธฐ
--- pod install
cd ios
pod install
cd ..
--- ์คํ
---- IOS
yarn react-native run-ios
---- Android
yarn react-native run-android
๐ ์ธํ
- ์กฐ๊ฑด
-- Reactotron setting
-- React-Navigation setting
-- tsconfig ์ ๋ ๊ฒฝ๋ก src
- ์ต์ข ์ปดํฌ๋ํธ ํธ๋ฆฌ
-- *์ฒดํฌ ๋์ด์๋ ๋ถ๋ถ์ ์๋ก ์์ฑํ๊ฑฐ๋ ํ์ผ์ ์ฎ๊ธฐ๋ ๊ฒ์ ๋๋ค.
|โโ ___test__
|โโ .bundle
|โโ .vscode (v)
| |โโ settings.json (v)
|โโ android
|โโ ios
|โโ src (v)
| |โโ activities (v)
| | |โโ pages (v)
| | | |โโ Home (v)
| | | | |โโ HomePage.tsx (v)
| | | | |โโ index.ts (v)
| |โโ assets (v)
| |โโ components (v)
| |โโ config (v)
| | |โโ ReactotronConfig.ts (v)
| | |โโ index.ts (v)
| |โโ navigators (v)
| | |โโ RootNavigator.tsx (v)
| | |โโ index.ts (v)
| |โโ routes (v)
| |โโ App.tsx (v)
|โโ index.js
- App.tsx
-- ๊ฒฝ๋ก : src
-- ํ์ผ ์ด๋ฆ : App.tsx
-- ์ฝ๋
import { NavigationContainer } from '@react-navigation/native'
import { AppContext, Context } from 'src/context'
import { RootNavigator } from 'src/navigators'
if (__DEV__) {
import('src/config/ReactotronConfig').then(() => console.log('Reactotron Configured'))
}
const App = () => {
return (
<NavigationContainer>
<Context.Provider value={new AppContext()}>
<RootNavigator />
</Context.Provider>
</NavigationContainer>
)
}
export default App
- RootNavigator.tsx
-- ๊ฒฝ๋ก : src/navigator
-- ํ์ผ ์ด๋ฆ : RootNavigator.tsx
-- ์ฝ๋
import { PageNavigator } from './PageNavigator'
export const RootNavigator = () => {
return <PageNavigator /> // ๋ค๋ฅธ ์์์ ๋ค๋น๊ฒ์ดํฐ๋ก
}
โ๏ธ Reactotron
๐ ์ค์น
- Reactotron App ์ค์น
brew install --cask reactotron
- ํ๋ก์ ํธ ํด๋์์ ์ค์น
-- ๊ฒฝ๋ก : /
yarn add -D reactotron-react-native @react-native-async-storage/async-storage
๐ ์ธํ
- config ํ์ผ ๋ง๋ค๊ธฐ
-- ๊ฒฝ๋ก : src/config
-- ํ์ผ ์ด๋ฆ : ReactotronConfig.ts
-- ์ฝ๋
import Reactotron from 'reactotron-react-native'
Reactotron
.configure() // controls connection & communication settings
.useReactNative() // add all built-in react native plugins
.connect() // let's connect!
- App.tsx์ ์ฝ๋ ์์ฑํ๊ธฐ
-- ๊ฒฝ๋ก : src
-- ํ์ผ ์ด๋ฆ : App.tsx
-- ์ฝ๋
if (__DEV__) {
import('src/config/ReactotronConfig').then(() => console.log('Reactotron Configured'))
}
โ๏ธ React Navigation
๐ ์ค์น
yarn add @react-navigation/native @react-navigation/stack react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view @react-navigation/native-stack
โ๏ธ Git
- .gitignore
-- ๊ฒฝ๋ก : /
-- ํ์ผ์ด๋ฆ : .gitignore
-- ์ฝ๋
# OSX
#
.DS_Store
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
# node.js
#
node_modules/
npm-debug.log
yarn-error.log
# BUCK
buck-out/
\\.buckd/
*.keystore
!debug.keystore
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# <https://docs.fastlane.tools/best-practices/source-control/>
*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots
# Bundle artifact
*.jsbundle
# CocoaPods
/ios/Pods/
# Environment Variables
.env
.env.development.local
.env.production.local
# .gitkeep
.gitkeep
- git remote
-- git remote
# connect
git remote add origin {address}
# confirm
git remote -v
-- ๋ณ๊ฒฝ์ฌํญ ์ ํ ํ add & commit
# add
git add .
# commit
git commit -m "commit message"
-- branch create
# master branch
git branch {branch name}
-- checkout
git checkout {branch name}
-- push
git push origin {branch name}
โ๏ธ NPM Script ์ค์
- package.json์ scripts
- pakage.json์ ์๋จ์ ์ฌ์ง์ฒ๋ผ ์ฝ๋ ์ถ๊ฐ ํ๊ธฐ
-- ํ๋จ์ ์ฝ๋๋ฅผ ๋ณต์ฌํ์๋ฉด ๋ฉ๋๋ค
"nodemodule_clean": "rm -rf node_modules/ && yarn cache clean",
"gradle-clean": "cd android && ./gradlew cleanBuildCache",
"watchman-metro-clean": "watchman watch-del-all && rm -rf $TMPDIR/metro-*",
"yarn-install": "yarn",
"pod-install": "cd ios && pod install",
"clean-start": "yarn start --reset-cache"
- NPM ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํด์ ์คํํ๊ธฐ
-- NPM ์คํฌ๋ฆฝํธ๊ฐ ๋นํ์ฑํ๋์ด์๋ค๋ฉด ํ์ฑํํ๊ธฐ
--- ์ฌ์ง ๊ณต๊ฐ์ ๋ง์ฐ์ค ์ฐํด๋ฆญํ๋ฉด ์ ๋ ํธ ๋ฐ์ค๊ฐ ๋ณด์ฌ์ง๋๋ค
- ์คํํ ๋๋ ํ์๋ ์์ด์ฝ์ ํด๋ฆญ