React Native 初次安裝踩坑

這次終於燃起了學習react的動力,在初步了解後開始進入react native的學習,更早之前其實有玩過expo,不過使用expo也會有些無法使用原生套件的問題,既然要先學習就從扎實的開始吧!

安裝react native

首先一開始我先安裝了全局

react-native init yourProjectName

後來在跑的時候卻報錯了

 typeError: cli.init is not a function

解決 :

方法是删除全局的react-native-cli

npm uninstall -g react-native-cli

隨後再次run了建立的指令,不意外的又報錯了....

bundle install
Your Ruby version is 2.6.6, but your Gemfile specified 2.7.5

於是繼續google,解決方案則是:

 將Gemfile裡的版本改成設置提示版本

#You can try these commands to install and change global Ruby version to 2.7.5

brew update
brew install ruby-build
brew install rbenv

# If you're using rvm:

rvm install 2.2.5
rvm use 2.2.5

# else if you're using rbenv:
rbenv install 2.7.5
rbenv global 2.7.5

#After that, you need to export some configurations to define rbenv as default global ruby:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc

其餘遇見的錯誤:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

解決:

直接去Apple 官網下載最新版本的Command Line Tools安裝即可,然後再通過brew config查看當前CLI版本號是否變更 鏈接:https://developer.apple.com/download/more/

Invariant Violation: new NativeEventEmitter() requires a non-null argument

解決:

Go to ios folder then remove

  1. Pods & Podfile.lock
  2. run pod install
  3. Rebuild project

安裝react-native-firebase後報錯

The following build commands failed: CompileC /Users/gbdev/Library/Developer/Xcode/DerivedData/GBWebApp-dgxghrfnprondmbkxeptlzyzcmeu/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-logger.build/Objects-normal/arm64/react_native_log.o /Users/gbdev/Desktop/ProgettiCA/rn-GBAppWeb/node_modules/react-native/ReactCommon/logger/react_native_log.cpp normal arm64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'React-logger' from project 'Pods') (1 failure)

解決:

將ios/your_app_name/AppDelegate.mm修改

#最上方添加
#import 

#刪除以下
if ([FIRApp defaultApp] == nil) {
    [FIRApp configure];
  }
#改為
[FIRApp configure];

 

Xcode 問題:

需要在真機上跑專案免不了要使用Xcode

The "App ID" cannot be registered to your development team. Change your bundle identifier to a unique string to try again

Failed to create provisioning profile

解決:

 

  • 點擊專案→ General → Identity → Bundle Identifier 換個名字 (隨便最後面加個數字也行)

安裝react-native-vector-icons 遇到:

Unrecognized font family 'Material Icons'

 在ios/your_app_name/info.plist中添加

	UIAppFonts
	
	AntDesign.ttf
	Entypo.ttf
	EvilIcons.ttf
	Feather.ttf
	FontAwesome.ttf
	FontAwesome5_Brands.ttf
	FontAwesome5_Regular.ttf
	FontAwesome5_Solid.ttf
	Foundation.ttf
	Ionicons.ttf
	MaterialIcons.ttf
	MaterialCommunityIcons.ttf
	SimpleLineIcons.ttf
	Octicons.ttf
	Zocial.ttf
	

安裝android studio時報錯:

Kotlin could not find the required JDK tools in the Java installation 

在終端開啟

~/.bash_profile

添加:
export ANDROID_HOME=/Users/{add_your_user_name}/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
export ANDROID_SDK=/Users/{add_your_user_name}/Library/Android/sdk
export PATH=/Users/{add_your_user_name}/Library/Android/sdk/platform-tools:$PATH

#別忘記trigger it
source ~/.bash_profile

其他問題遇到持續在更新~

你可能感兴趣的:(react,native,react.js,javascript)