集成過程可以參考官網(wǎng)
https://www.react-native.cn/docs/environment-setup
安裝
可完全參考上述官網(wǎng)的步驟
安裝Node
brew install node
安裝Watchman
brew install watchman
設(shè)置npm鏡像源
如果不設(shè)置成國內(nèi)鏡像,在后期開發(fā)過程中境析,npm包下載速度很慢或存在無法下載的情況囚枪。
npm config set registry [https://registry.npm.taobao.org](https://registry.npm.taobao.org/) --global
npm config set disturl [https://npm.taobao.org/dist](https://npm.taobao.org/dist) --global
安裝工具
npm install -g yarn react-native-cli
設(shè)置鏡像源
yarn config set registry [https://registry.npm.taobao.org](https://registry.npm.taobao.org/) --global
yarn config set disturl [https://npm.taobao.org/dist](https://npm.taobao.org/dist) --global
初始化工程
react-native init TestRN
1.react-native init TypeError: cli.init is not a function-------------yarn add react-native ——————exact
init失敗,error Error: Command failed: yarn add react-native@latest------------npm install -g yarn-----npx react-native init TestRN或者二次init
卸載重裝
查看 gem -list
卸載sudo gem uninstall cocoapods
下載demo簿晓,啟動npm install失敗----------npm install --registry=https://registry.npm.taobao.org
其他問題
安裝yarn后眶拉,使用yarn命令找不到
1.open ~/.bash_profile
2.export PATH="$PATH:/Users/lushuang/.yarn/bin"
3.source ~/.bash_profile
4.yarn -version
NA + RN 參考官網(wǎng)https://www.react-native.cn/docs/integration-with-existing-apps
1.ios文件夾
2.package.json
3.yarn add react-native---- Error: unable to get local issuer certificate------yarn config set strict-ssl false
3.index.js
運(yùn)行Metro
source ~/.bash_profile
yarn start
或 npm start
真機(jī)調(diào)試
-U and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together
方案:Podfile文件:use_frameworks! :linkage => :static
真機(jī)bundle
*創(chuàng)建/iOS/bundle/index.jsbundle
*根目錄執(zhí)行一下命令
react-native bundle --entry-file ./index.js --bundle-output ./ios/bundle/index.jsbundle --platform ios --assets-dest ./ios/bundle --dev false
*xcode工程添加上述jsbundle文件
*真機(jī)運(yùn)行
demo 如下
直接下載下來千埃,執(zhí)行 sh initdemo.sh 即可 https://github.com/shuang0124/iOSNAWithRN.git