這次終於燃起了學習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
將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
安裝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 <Firebase.h>
#刪除以下
if ([FIRApp defaultApp] == nil) {
[FIRApp configure];
}
#改為
[FIRApp configure];
需要在真機上跑專案免不了要使用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
安裝react-native-vector-icons 遇到:
Unrecognized font family 'Material Icons'
在ios/your_app_name/info.plist中添加
<key>UIAppFonts</key>
<array>
<string>AntDesign.ttf</string>
<string>Entypo.ttf</string>
<string>EvilIcons.ttf</string>
<string>Feather.ttf</string>
<string>FontAwesome.ttf</string>
<string>FontAwesome5_Brands.ttf</string>
<string>FontAwesome5_Regular.ttf</string>
<string>FontAwesome5_Solid.ttf</string>
<string>Foundation.ttf</string>
<string>Ionicons.ttf</string>
<string>MaterialIcons.ttf</string>
<string>MaterialCommunityIcons.ttf</string>
<string>SimpleLineIcons.ttf</string>
<string>Octicons.ttf</string>
<string>Zocial.ttf</string>
</array>
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