我需要橋接嗎?
通常不需要。SQLite Viewer 可以透過 USB 直接與手機通訊(Chrome 或 Edge 中的 USB 直連模式),無需安裝任何東西。橋接只用於一種情況:Android Studio(或其他 ADB 工具)已在使用手機。USB 連線同一時間只能由一個程式佔用,因此橋接讓 SQLite Viewer 共用 Android Studio 的 ADB 伺服器,兩者便能同時運作。
| USB 直連 | ADB 伺服器(橋接) | |
|---|---|---|
| 需要安裝嗎? | 不需要 | 需要,一次(Windows 上一鍵完成) |
| Android Studio 開啟時能用嗎? | 不能,必須關閉 | 能 |
| 瀏覽器 | 桌面版 Chrome 或 Edge | 任何現代瀏覽器 |
| 電腦上需要 ADB 嗎? | 不需要 | 需要(Android Studio 或 Platform Tools) |
Windows:一鍵安裝程式
- 下載安裝程式。在 SQLite Viewer 中開啟 Live Android,選擇 ADB 伺服器,然後點選下載安裝程式 (Windows)。
- 保留檔案。Chrome 可能提示無法驗證該檔案。請選擇保留(或下載未驗證的檔案)。該檔案是純文字,您可以用記事本開啟,查看它具體做了什麼。
- 執行一次。按兩下
Install-ADB-Bridge.cmd。如果 Windows 顯示Windows 已保護您的電腦,請點選其他資訊,再點選仍要執行。 - 回到頁面。安裝程式會在您的電腦上建置橋接程式,讓它在每次登入時自動啟動,並立即啟動它。SQLite Viewer 會在幾秒內發現它。點選透過橋接連線。
橋接程式安裝在 %LOCALAPPDATA%\SQLiteViewerBridge,啟動資料夾中的捷徑會在登入時啟動它。要移除它,請從該資料夾執行 uninstall.cmd。
任何系統:使用 Python 設定
- 安裝 Python 3。從 python.org 下載。在 Windows 上,請在安裝程式中勾選 Add Python to PATH。大多數 Linux 系統已內建
python3。macOS 預設不包含它:第一次輸入python3時,macOS 會提示安裝 Apple 的命令列工具(請接受),或使用 python.org 的安裝程式。 - 下載檔案。下載 adb-bridge.py。瀏覽器會將其儲存到「下載」資料夾。如果檔名以
.txt結尾,請重新命名為adb-bridge.py。 - 將它複製到固定位置。開啟終端機(任意資料夾均可,指令使用完整路徑),執行適合您系統的指令。它會建立資料夾並把檔案複製進去。如果瀏覽器把檔案儲存在「下載」以外的位置,請修改指令中的那一部分。
- 讓它自動啟動。執行適合您系統的指令。它會為您複製到的檔案設定登入時啟動項目,並立即啟動橋接程式。
- 連線。回到 SQLite Viewer,它會自動找到橋接程式。點選透過橋接連線。
步驟 3:複製檔案(執行一次)
Windows(PowerShell,按 Windows 鍵,輸入 powershell,按 Enter):
New-Item -ItemType Directory -Force "$env:LOCALAPPDATA\SQLiteViewerBridgePython" | Out-Null; Copy-Item "$env:USERPROFILE\Downloads\adb-bridge.py" "$env:LOCALAPPDATA\SQLiteViewerBridgePython\adb-bridge.py"
Windows(命令提示字元,按 Windows 鍵,輸入 cmd,按 Enter):
mkdir "%LOCALAPPDATA%\SQLiteViewerBridgePython" & copy "%USERPROFILE%\Downloads\adb-bridge.py" "%LOCALAPPDATA%\SQLiteViewerBridgePython\adb-bridge.py"
macOS(終端機):
mkdir -p "$HOME/Library/Application Support/SQLiteViewerBridge" && cp "$HOME/Downloads/adb-bridge.py" "$HOME/Library/Application Support/SQLiteViewerBridge/adb-bridge.py"
Linux:
mkdir -p "$HOME/.local/share/sqliteviewer-bridge" && cp "$HOME/Downloads/adb-bridge.py" "$HOME/.local/share/sqliteviewer-bridge/adb-bridge.py"
步驟 4:登入時自動啟動(執行一次)
Windows (PowerShell):
python "$env:LOCALAPPDATA\SQLiteViewerBridgePython\adb-bridge.py" --add-to-startup
Windows(命令提示字元):
python "%LOCALAPPDATA%\SQLiteViewerBridgePython\adb-bridge.py" --add-to-startup
macOS:
python3 "$HOME/Library/Application Support/SQLiteViewerBridge/adb-bridge.py" --add-to-startup
Linux:
python3 "$HOME/.local/share/sqliteviewer-bridge/adb-bridge.py" --add-to-startup
在 Windows 上,這會在啟動資料夾中建立一個隱藏的捷徑;在 macOS 上建立 Launch Agent;在 Linux 上建立 systemd 使用者服務(或桌面自動啟動項目)。它們都不需要系統管理員權限。請讓檔案保持在原位置;如果移動了它,請再次執行指令。
趕時間?一個指令完成步驟 3 和步驟 4
在您下載檔案的資料夾中開啟終端機並執行:
python adb-bridge.py --install # Windows python3 adb-bridge.py --install # macOS and Linux
想手動加入啟動項目?
Windows:按 Win + R,輸入 shell:startup 並按 Enter。在開啟的資料夾中按右鍵,選擇新增 → 捷徑,並將位置設為:
pythonw "%LOCALAPPDATA%\SQLiteViewerBridgePython\adb-bridge.py"
命名為 SQLite Viewer ADB Bridge。使用 pythonw 而不是 python 可避免出現黑色視窗。登出後重新登入,或按兩下該捷徑立即啟動。
macOS:上面的指令會建立 ~/Library/LaunchAgents/com.sqliteviewer.adbbridge.plist。Linux:會建立 ~/.config/systemd/user/sqliteviewer-bridge.service(或 ~/.config/autostart/sqliteviewer-bridge.desktop)。手動撰寫這些檔案也是可行的,但使用指令更安全。
檢查、停止和移除
python adb-bridge.py --status # is it running? python adb-bridge.py --remove-from-startup # stop starting at sign-in (keeps the file) python adb-bridge.py --uninstall # stop it and delete everything # add the full path to the file if you are not in its folder, as in the commands above
我有 ADB 嗎?沒有就安裝
橋接程式會轉送到 ADB(Android Platform Tools)。Android Studio 已內建它,所以如果您使用 Android Studio,可以略過本節。要檢查,請開啟終端機並執行 adb version。如果系統不認得該指令,請用下面的某個指令安裝 ADB。當橋接程式在執行但找不到 ADB 時,SQLite Viewer 也會告訴您。橋接程式會在 PATH 以及常見的 Android Studio、winget、Homebrew 和手動下載資料夾中尋找 ADB,因此您無需修改 PATH,它還會為您啟動 ADB 伺服器。
Windows
最簡單的方式(Windows 10 和 11,PowerShell 或命令提示字元):
winget install --id Google.PlatformTools -e
沒有 winget?直接下載 (PowerShell):
Invoke-WebRequest https://dl.google.com/android/repository/platform-tools-latest-windows.zip -OutFile "$env:TEMP\pt.zip"; Expand-Archive "$env:TEMP\pt.zip" "$env:LOCALAPPDATA\Android\Sdk" -Force; Remove-Item "$env:TEMP\pt.zip"
命令提示字元中的相同操作:
powershell -NoProfile -Command "Invoke-WebRequest https://dl.google.com/android/repository/platform-tools-latest-windows.zip -OutFile \"$env:TEMP\pt.zip\"; Expand-Archive \"$env:TEMP\pt.zip\" \"$env:LOCALAPPDATA\Android\Sdk\" -Force; Remove-Item \"$env:TEMP\pt.zip\""
檢查是否成功 (PowerShell):
& "$env:LOCALAPPDATA\Android\Sdk\platform-tools\adb.exe" version
macOS
使用 Homebrew:
brew install --cask android-platform-tools
不使用 Homebrew:
mkdir -p "$HOME/Library/Android/sdk" && curl -L -o /tmp/pt.zip https://dl.google.com/android/repository/platform-tools-latest-darwin.zip && unzip -o /tmp/pt.zip -d "$HOME/Library/Android/sdk" && rm /tmp/pt.zip
Linux
Debian、Ubuntu、Mint:
sudo apt install adb
Fedora:
sudo dnf install android-tools
Arch、Manjaro:
sudo pacman -S android-tools
其他任何發行版:
mkdir -p "$HOME/Android/Sdk" && curl -L -o /tmp/pt.zip https://dl.google.com/android/repository/platform-tools-latest-linux.zip && unzip -o /tmp/pt.zip -d "$HOME/Android/Sdk" && rm /tmp/pt.zip
然後準備手機
- 在手機上開啟設定 → 關於手機,連續點選版本號碼七次。
- 開啟設定 → 開發人員選項,開啟 USB 偵錯。
- 連接手機並在提示上點選允許。執行
adb devices應將其列為device。
我需要設定什麼嗎?
不需要。橋接程式只接受來自 SQLite Viewer 網站的連線,只在您自己的電腦上接聽 (127.0.0.1),並且只轉送到同一台電腦上的 ADB 伺服器。不會在其他任何地方儲存或傳送任何內容。
只有兩種情況需要設定:
- 您從其他位址使用 SQLite Viewer(您自己的副本,或開發時的
localhost)。請在相同的指令中允許該位址:
python "%LOCALAPPDATA%\SQLiteViewerBridgePython\adb-bridge.py" --add-to-startup --allow-origin https://your-address.example
- 連接埠 5038 已被佔用。請使用其他連接埠,然後在 Android 面板的進階中輸入相同的連接埠:
python "%LOCALAPPDATA%\SQLiteViewerBridgePython\adb-bridge.py" --add-to-startup --port 5040
允許的位址會記錄在橋接程式旁名為 origins.txt 的檔案中(每行一個位址):Windows 為 %LOCALAPPDATA%\SQLiteViewerBridge(安裝程式)或 %LOCALAPPDATA%\SQLiteViewerBridgePython (Python),macOS 為 ~/Library/Application Support/SQLiteViewerBridge,Linux 為 ~/.local/share/sqliteviewer-bridge。
疑難排解
- 「此電腦上未執行橋接程式」:執行安裝程式或上面的指令,或登出後重新登入。然後重新開啟 Android 面板。
- 我沒有 Python:在 Windows 上不需要,請使用上面的一鍵安裝程式。否則請從 python.org 安裝 Python 3(Windows:勾選 Add Python to PATH),或在 macOS 上接受安裝命令列工具的提示。然後再次執行指令。
python無法辨識,或開啟 Microsoft Store (Windows):尚未安裝 Python,或漏選了 PATH 選項。請從 python.org 安裝,或在指令中將python替換為py。您也可以在設定 → 應用程式 → 進階應用程式設定 → 應用程式執行別名中關閉市集捷徑。- 複製指令提示找不到檔案:瀏覽器把
adb-bridge.py儲存在了「下載」以外的位置。請修改指令中的那一部分,或重新命名.txt檔案。 - 「連接埠 5038 已被佔用」:另一個橋接程式正在執行。請移除舊的(
--uninstall或uninstall.cmd),或使用--port選擇其他連接埠。 - 橋接程式在執行但看不到手機:ADB 伺服器必須能看到手機。執行
adb devices,開啟 USB 偵錯,並在手機上接受「允許 USB 偵錯」提示。 - 「橋接程式在執行,但未安裝 ADB」:請用上面我有 ADB 嗎?一節中的指令安裝 ADB(或安裝 Android Studio)。幾秒鐘後頁面會自動發現。
- Chrome 詢問是否允許存取您網路中的裝置:請允許。頁面正是透過這種方式連到您自己電腦上的橋接程式。
- 防毒軟體或 Windows 封鎖了安裝程式:安裝程式只是根據您可以閱讀的原始碼建置一個小程式,並寫入您自己的使用者資料夾。請允許它,或改用 Python 方式。