mkdir ~/.npm-global
先建立一個新資料夾來讓全域 package 使用。
mkdir ~/.npm-global
mkdir: /Users/minjing/.npm-global: File exists
訊息提示已有同名資料夾存在。
npm config set prefix '~/.npm-global'
設置 npm 使用這個路徑。
用 open ~/.zshrc
打開 iTerm terminal 的設定檔。
它會用文字編輯程式打開,插入 export PATH=~/.npm-global/bin:$PATH
,然後將 zshrc 檔案存檔。
terminal 中使用 source ~/.zshrc
來更新 terminal 設置。
然後使用 npm install -g expo-cli
安裝 Expo CLI 工具。
npx expo start --clear
清除 Expo 快取。
npx expo prebuild --clean
重新建立本機專案。
結果建立途中,發生 google-services.json
檔案未存在專案目錄的錯誤。
✖ Prebuild failed
Error: [android.dangerous]: withAndroidDangerousBaseMod: Cannot copy google-services.json from /Users/minjing/development/jim/NotificationProgress/google-services.json to /Users/minjing/development/jim/NotificationProgress/android/app/google-services.json. Please make sure the source and destination paths exist
至 Firebase 主控台下載 google-services.json
檔案,放至專案根目錄。
再執行一次 npx expo prebuild --clean
> npx expo prebuild --clean
Warning! Your git working tree is dirty.
It's recommended to commit all your changes before proceeding, so you can revert the changes made by this command if necessary.
✔ Would you like to proceed? … yes
✔ Cleared android, ios code
✔ Created native directories
✔ Updated package.json | no changes
» android: userInterfaceStyle: Install expo-system-ui in your project to enable this feature.
✔ Finished prebuild
⚠️ Something went wrong running `pod install` in the `ios` directory.
Command `pod install` failed.
└─ Cause: Failed to load 'hermes-engine' podspec:
[!] Invalid `hermes-engine.podspec` file: undefined method `visionos' for #<Pod::Specification name="hermes-engine/Pre-built">.
# from /Users/minjing/development/jim/NotificationProgress/node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec:47
# -------------------------------------------
# ss.ios.vendored_frameworks = "destroot/Library/Frameworks/universal/hermes.xcframework"
> ss.visionos.vendored_frameworks = "destroot/Library/Frameworks/universal/hermes.xcframework"
# ss.osx.vendored_frameworks = "destroot/Library/Frameworks/macosx/hermes.framework"
# -------------------------------------------
pod install --repo-update --ansi exited with non-zero code: 1
看到 Android 構建成功。
使用 npx expo run:android
來運行 Android 應用程式。