iT邦幫忙

2024 iThome 鐵人賽

DAY 12
0

在設定好 Mac 電腦所使用的 JVM 版本,接著用 npx expo run:android --device 指令來在本機端建置 Android 原生應用程式。

看到有 adb 安裝失敗的訊息。

[ADB] Couldn't reverse port 8081: adb: error: closed
Error: adb: failed to install /Users/minjing/development/jim/NotificationProgress/android/app/build/outputs/apk/debug/app-debug.apk:
Error: /Users/minjing/Library/Android/sdk/platform-tools/adb -s (實體手機裝置ID) install -r -d --user 0 /Users/minjing/development/jim/NotificationProgress/android/app/build/outputs/apk/debug/app-debug.apk exited with non-zero code: 1
    at ChildProcess.completionListener (/Users/minjing/development/jim/NotificationProgress/node_modules/@expo/spawn-async/src/spawnAsync.ts:67:13)
    at Object.onceWrapper (node:events:634:26)
    at ChildProcess.emit (node:events:519:28)
    at maybeClose (node:internal/child_process:1105:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)
    at Socket.emit (node:events:519:28)
    at Pipe.<anonymous> (node:net:339:12)
    ...
    at spawnAsync (/Users/minjing/development/jim/NotificationProgress/node_modules/@expo/spawn-async/src/spawnAsync.ts:28:21)
    at ADBServer.runAsync (/Users/minjing/development/jim/NotificationProgress/node_modules/@expo/cli/src/start/platforms/android/ADBServer.ts:85:59)
    at Object.installAsync (/Users/minjing/development/jim/NotificationProgress/node_modules/@expo/cli/src/start/platforms/android/adb.ts:217:10)
    at AndroidDeviceManager.installAppAsync (/Users/minjing/development/jim/NotificationProgress/node_modules/@expo/cli/src/start/platforms/android/AndroidDeviceManager.ts:85:5)
    at installAppAsync (/Users/minjing/development/jim/NotificationProgress/node_modules/@expo/cli/src/run/android/runAndroidAsync.ts:75:5)
    at runAndroidAsync (/Users/minjing/development/jim/NotificationProgress/node_modules/@expo/cli/src/run/android/runAndroidAsync.ts:50:3)

先使用下列指令把 adb 程序移除再重新啟用。

adb kill-server
adb start-server

接著提示需要先登入才能使用 EAS 服務。

An Expo user account is required to proceed.

Log in to EAS with email or username (exit and run 'npx expo login --help' for other login options)
✔ Email or username … (帳號)
✔ Password …  (密碼)
ApiV2Error: Your username, email, or password was incorrect.

如果輸入錯誤的帳號、密碼,使用 npx expo login 來重新進入登入程序。

登入完畢後,使用 npx expo start 來啟動應用程式。

> npx expo start
Starting project at /Users/minjing/development/jim/NotificationProgress
Starting Metro Bundler
The following packages should be updated for best compatibility with the installed expo version:
  expo-notifications@0.28.16 - expected version: ~0.28.17
Your project may not work correctly until you install the expected versions of the packages.

(省略 QR Code)

› Metro waiting on exp://(省略)
› Scan the QR code above with Expo Go (Android) or the Camera app (iOS)

› Using Expo Go
› Press s │ switch to development build

› Press a │ open Android
› Press i │ open iOS simulator
› Press w │ open web

› Press j │ open debugger
› Press r │ reload app
› Press m │ toggle menu
› Press o │ open project code in your editor

› Press ? │ show all commands

Logs for your project will appear below. Press Ctrl+C to exit.
› Opening on Android...
› Opening exp://(省略) on Pixel_6
› Press ? │ show all commands
Android Bundled 464ms node_modules/expo/AppEntry.js (750 modules)
 LOG  ExponentPushToken[(省略)]

可以看到專案編號有設定成功(沒顯示與專案編號有關的錯誤),以及有顯示 ExponentPushToken。


上一篇
[Day 11] Mac 電腦指定 JVM 版本
下一篇
[Day 13] React Expo Notification 範例解說
系列文
跨平台協同:在 React Native 和 Kotlin 應用中實現無縫交互 -以 Notification 為例30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言