feat(dev): add Android live-reload workflow with SDK autodetection
- Add root dev:android script delegating to frontend - Add Android dev scripts and wrapper to resolve ANDROID_SDK_ROOT/ANDROID_HOME (Linux/WSL) - Keep Vite running when Android run fails and document troubleshooting in frontend README - Ignore generated frontend/android project in git
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -21,5 +21,6 @@ __pycache__/
|
||||
node_modules/
|
||||
frontend/node_modules/
|
||||
frontend/dist/
|
||||
frontend/android/
|
||||
frontend/release/
|
||||
release/
|
||||
|
||||
@@ -1,16 +1,69 @@
|
||||
# React + Vite
|
||||
# Frontend (Electron + Android)
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
## Prerequisites
|
||||
|
||||
Currently, two official plugins are available:
|
||||
- Node.js and npm
|
||||
- Android SDK + `adb` + an emulator or connected device (for Android dev mode)
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||
## Install dependencies
|
||||
|
||||
## React Compiler
|
||||
From repository root:
|
||||
|
||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
||||
```bash
|
||||
cd frontend
|
||||
npm ci
|
||||
```
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
## Development
|
||||
|
||||
If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
|
||||
From repository root:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
This starts desktop development mode (Vite + Electron).
|
||||
|
||||
From repository root:
|
||||
|
||||
```bash
|
||||
npm run dev:android
|
||||
```
|
||||
|
||||
This starts Android live-reload development mode:
|
||||
|
||||
- Ensures `frontend/android` exists (`cap add android` on first run only)
|
||||
- Starts Vite on `0.0.0.0:5173`
|
||||
- Runs `cap run android -l --no-sync --port 5173 --forwardPorts 5173:5173`
|
||||
|
||||
## Troubleshooting (Android SDK)
|
||||
|
||||
If you get:
|
||||
|
||||
```text
|
||||
ERR_SDK_NOT_FOUND: No valid Android SDK root found.
|
||||
```
|
||||
|
||||
set one of these environment variables and run again:
|
||||
|
||||
```bash
|
||||
export ANDROID_SDK_ROOT="/path/to/Android/Sdk"
|
||||
# or
|
||||
export ANDROID_HOME="/path/to/Android/Sdk"
|
||||
```
|
||||
|
||||
Typical locations:
|
||||
|
||||
- Linux: `$HOME/Android/Sdk`
|
||||
- WSL + Android Studio on Windows: `/mnt/c/Users/<windows-user>/AppData/Local/Android/Sdk`
|
||||
|
||||
## Other scripts
|
||||
|
||||
From `frontend/`:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
npm run preview
|
||||
npm run cap:sync
|
||||
npm run dist
|
||||
```
|
||||
|
||||
@@ -5,12 +5,16 @@
|
||||
"type": "module",
|
||||
"main": "electron/main.cjs",
|
||||
"scripts": {
|
||||
"vite": "vite",
|
||||
"dev": "concurrently --kill-others -n Vite,Electron \"vite\" \"wait-on http://localhost:5173 && cross-env NODE_ENV=development ELECTRON_RUN_AS_NODE= electron .\"",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"dist": "vite build && electron-builder",
|
||||
"cap:sync": "vite build && cap sync android"
|
||||
"vite": "vite",
|
||||
"dev": "concurrently --kill-others -n Vite,Electron \"vite\" \"wait-on http://localhost:5173 && cross-env NODE_ENV=development ELECTRON_RUN_AS_NODE= electron .\"",
|
||||
"android:ensure": "sh -c '[ -d android ] || cap add android'",
|
||||
"dev:web:android": "vite --host 0.0.0.0 --port 5173",
|
||||
"dev:android:run": "wait-on tcp:5173 && sh ./scripts/cap-run-android-live.sh",
|
||||
"dev:android": "npm run android:ensure && concurrently -n Vite,Android \"npm run dev:web:android\" \"npm run dev:android:run\"",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"dist": "vite build && electron-builder",
|
||||
"cap:sync": "vite build && cap sync android"
|
||||
},
|
||||
"build": {
|
||||
"appId": "com.walletgen.app",
|
||||
|
||||
47
frontend/scripts/cap-run-android-live.sh
Normal file
47
frontend/scripts/cap-run-android-live.sh
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
find_sdk() {
|
||||
if [ -n "${ANDROID_SDK_ROOT:-}" ] && [ -d "${ANDROID_SDK_ROOT}" ]; then
|
||||
printf '%s' "${ANDROID_SDK_ROOT}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -n "${ANDROID_HOME:-}" ] && [ -d "${ANDROID_HOME}" ]; then
|
||||
printf '%s' "${ANDROID_HOME}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -d "${HOME}/Android/Sdk" ]; then
|
||||
printf '%s' "${HOME}/Android/Sdk"
|
||||
return 0
|
||||
fi
|
||||
|
||||
for candidate in /mnt/c/Users/*/AppData/Local/Android/Sdk; do
|
||||
if [ -d "${candidate}" ]; then
|
||||
printf '%s' "${candidate}"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
if ! SDK_PATH="$(find_sdk)"; then
|
||||
echo "ERROR: Android SDK non trovato."
|
||||
echo
|
||||
echo "Imposta una delle due variabili e riprova:"
|
||||
echo " export ANDROID_SDK_ROOT=\"/path/to/Android/Sdk\""
|
||||
echo " export ANDROID_HOME=\"/path/to/Android/Sdk\""
|
||||
echo
|
||||
echo "Percorsi tipici:"
|
||||
echo " Linux: \$HOME/Android/Sdk"
|
||||
echo " WSL: /mnt/c/Users/<utente>/AppData/Local/Android/Sdk"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export ANDROID_SDK_ROOT="${SDK_PATH}"
|
||||
export ANDROID_HOME="${ANDROID_HOME:-${SDK_PATH}}"
|
||||
export PATH="${ANDROID_SDK_ROOT}/platform-tools:${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin:${PATH}"
|
||||
|
||||
exec cap run android -l --no-sync --port 5173 --forwardPorts 5173:5173
|
||||
@@ -2,6 +2,7 @@
|
||||
"name": "address-gen",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "cd frontend && npm run dev"
|
||||
"dev": "cd frontend && npm run dev",
|
||||
"dev:android": "cd frontend && npm run dev:android"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user