This is a cross-platform Bluetooth Low Energy (BLE) application example based on Tauri + Vue 3 + TypeScript. It supports Bluetooth device communication on Windows, macOS, Linux, and Android platforms.
| Component | Version | Description |
|---|---|---|
| Node.js | ≥ 18.0 | JavaScript runtime |
| Rust | Latest Stable | Backend development language |
| Tauri CLI | ≥ 2.0 | Tauri command-line tool |
| Android SDK | API 21+ | Android development only |
| JDK | 11+ | Android development only |
git clone https://github.com/your-repo/tauri-ble-example.git
cd tauri-ble-example# Check Node.js version
node --version
npm --version
# If not installed, download from https://nodejs.org/
# Recommended: Use NVM for version management, download from https://github.com/coreybutler/nvm-windows
nvm install latest
nvm use latest# Install Rust using rustup (recommended)
# Visit https://rustup.rs/ or execute
irm https://rustup.rs | iex
# Verify installation
rustc --version
cargo --version
# Update Rust (recommended weekly)
rustup update# Install Tauri CLI globally
cargo install tauri-cli
# Verify installation
cargo tauri --version# Install npm dependencies
npm install# Run Tauri application in development mode
cargo tauri devThe application will run in development mode with hot reload support
# Build frontend only
npm run build
# Build desktop application
cargo tauri buildBuild output locations:
- Windows:
src-tauri/target/release/ - macOS:
src-tauri/target/release/
# Install JDK 11+ (recommended)
# Download from https://www.oracle.com/java/technologies/downloads/
# Or use
choco install openjdk
# Verify
java -version# Download Android Studio
# https://developer.android.com/studio
# Or use command-line tools (cmdline-tools)
# Set ANDROID_SDK_ROOT environment variable
[Environment]::SetEnvironmentVariable("ANDROID_SDK_ROOT", "C:\Users\YourUsername\AppData\Local\Android\Sdk", [EnvironmentVariableTarget]::User)
[Environment]::SetEnvironmentVariable("ANDROID_HOME", "C:\Users\YourUsername\AppData\Local\Android\Sdk", [EnvironmentVariableTarget]::User)
# Refresh environment variables
$env:ANDROID_SDK_ROOT = [System.Environment]::GetEnvironmentVariable("ANDROID_SDK_ROOT","User")
$env:ANDROID_HOME = [System.Environment]::GetEnvironmentVariable("ANDROID_HOME","User")
# Verify
echo $env:ANDROID_SDK_ROOT# Add Android compilation targets
rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi
rustup target add x86_64-linux-android
rustup target add i686-linux-android
# List installed targets
rustup target list | findstr "installed"
⚠️ Security Note: Application signing keys are critical. Store them securely!
Create a Keystore for first-time build:
# Generate keystore using keytool (requires JDK)
keytool -genkey -v -keystore tauri-ble-example-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload
# Follow the prompts to enter:
# - Keystore password
# - Key password
# - Country code, city, and other informationCreate local.properties file:
Create local.properties in the src-tauri/gen/android/ directory with the following content:
# Signing configuration (replace with your actual values)
storePassword=your_keystore_password
keyPassword=your_key_password
keyAlias=upload
storeFile=C:\\path\\to\\your\\tauri-ble-example-keystore.jksValue descriptions:
your_keystore_password: Password set when creating the keystoreyour_key_password: Password set when creating the keyC:\\path\\to\\your\\tauri-ble-example-keystore.jks: Full path to the keystore file
# Build APK (with signature)
cargo tauri android buildAPK location: src-tauri/gen/android/app/build/outputs/apk/
-
Never leak key information:
- 🚫 Do NOT commit
local.propertiesto Git repository - 🚫 Do NOT upload keystore files (
.jks) to public repositories - 🚫 Do NOT expose keys in code comments or documentation
- 🚫 Do NOT share your signing passwords with anyone
- 🚫 Do NOT commit
-
Keystore Loss Handling:
- If the keystore is lost or compromised, you must generate a new signing key for your app
- You cannot re-sign previously released apps with a new key
- Recommended to maintain backups in a secure location
-
Environment Variables Approach (Recommended):
# Set environment variables instead of hardcoding in files
[Environment]::SetEnvironmentVariable("KEYSTORE_PASSWORD", "your_password", [EnvironmentVariableTarget]::User)
[Environment]::SetEnvironmentVariable("KEY_PASSWORD", "your_password", [EnvironmentVariableTarget]::User)
[Environment]::SetEnvironmentVariable("KEYSTORE_PATH", "C:\path\to\keystore.jks", [EnvironmentVariableTarget]::User)
# Verify
$env:KEYSTORE_PASSWORDAdd the following lines to .gitignore (if not already added):
# Android local configuration
src-tauri/gen/android/local.properties
# Keystore files
*.jks
*.keystore
# Gradle files
src-tauri/gen/android/.gradle/
src-tauri/gen/android/build/
# IDE configuration
.idea/
*.imlUse GitHub Secrets or similar key management services to protect keys in CI/CD workflows
tauri-ble-example/
├── src/ # Vue frontend code
│ ├── App.vue # Main application component
│ ├── main.ts # Application entry point
│ └── index.css # Style file
├── src-tauri/ # Rust backend code
│ ├── gen/
│ │ ├── android/ # Android related files
│ │ │ ├── local.properties # Local configuration file (should not be committed to version control)
│ │ │ ├── ...
│ ├── src/
│ │ ├── lib.rs # Rust library file
│ │ └── main.rs # Rust main file
│ ├── Cargo.toml # Rust dependencies configuration
│ ├── tauri.conf.json # Tauri configuration file
│ └── capabilities/ # Permission configuration
├── public/ # Static assets
├── package.json # npm dependencies
├── tsconfig.json # TypeScript configuration
└── vite.config.ts # Vite configuration| Command | Description |
|---|---|
npm run dev |
Start frontend development server |
npm run build |
Build frontend assets |
cargo tauri dev |
Run desktop application in development mode |
cargo tauri build |
Build and package desktop application |
cargo tauri android dev |
Run Android application in development mode |
cargo tauri android build |
Build and package Android application |
This project integrates the tauri-plugin-blec plugin, providing cross-platform Bluetooth Low Energy support.
- 📡 Scan Bluetooth devices
- 🔗 Connect/disconnect devices
- 📨 Read/write characteristics
- 🔔 Subscribe to notifications
- 🦀 Rust Official Documentation
- 🎨 Vue 3 Documentation
- 🚀 Tauri Official Documentation
- 📱 Tauri Mobile Documentation
- 🔌 tauri-plugin-blec
- 🤖 Android Official Documentation
-
Use VS Code: Install recommended extensions
- Vue - Official
- Tauri
- rust-analyzer
- TypeScript Vue Plugin
-
Debugging Tips:
- Frontend: Use Vue DevTools
- Rust: Set
RUST_LOG=debugto view logs - On Android: Use
logcat tauri_ble_example:D '*:S'to view Rust-side logs
-
Performance Optimization:
- Use
npm run buildto generate optimized production version - Leverage Vite's code splitting feature
- Use
-
Version Management:
- Regularly run
rustup update - Regularly run
npm update
- Regularly run
MIT License - See LICENSE file for details
