惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
B
Blog
V
V2EX
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
博客园 - 聂微东
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
J
Java Code Geeks
H
Help Net Security
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
D
Docker
L
LangChain Blog
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
WordPress大学
WordPress大学
V
Visual Studio Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
APK Install and App Manager in Rust + Tauri — Building AD...
hiyoyo · 2026-06-14 · via DEV Community
Cover image for APK Install and App Manager in Rust + Tauri — Building ADB Tools

hiyoyo

All tests run on an 8-year-old MacBook Air. All results from shipping 7 Mac apps as a solo developer. No sponsored opinion.

HiyokoKit includes APK installation and an Android app manager. Both use ADB under the hood. Here's the implementation.


APK installation

#[tauri::command]
async fn install_apk(apk_path: String) -> Result<String, AppError> {
    let output = tokio::process::Command::new("adb")
        .args(["install", "-r", &apk_path]) // -r = reinstall if exists
        .output()
        .await?;

    let stdout = String::from_utf8_lossy(&output.stdout);
    let stderr = String::from_utf8_lossy(&output.stderr);

    if stdout.contains("Success") {
        Ok("Installation successful".into())
    } else {
        let error = if stderr.contains("INSTALL_FAILED_VERSION_DOWNGRADE") {
            "Cannot install older version over newer. Use -d flag to downgrade."
        } else if stderr.contains("INSTALL_FAILED_ALREADY_EXISTS") {
            "App already installed. Use reinstall option."
        } else {
            "Installation failed"
        };
        Err(AppError::Adb(error.into()))
    }
}

Parse the specific error codes — generic "installation failed" isn't useful to users.


App list

#[derive(Serialize)]
pub struct AppInfo {
    package_name: String,
    is_system: bool,
}

#[tauri::command]
async fn list_apps(include_system: bool) -> Result<Vec<AppInfo>, AppError> {
    let flag = if include_system { "-l" } else { "-3" }; // -3 = third-party only

    let output = tokio::process::Command::new("adb")
        .args(["shell", "pm", "list", "packages", flag])
        .output()
        .await?;

    let apps = String::from_utf8_lossy(&output.stdout)
        .lines()
        .filter_map(|line| {
            line.strip_prefix("package:").map(|pkg| AppInfo {
                package_name: pkg.trim().to_string(),
                is_system: !include_system,
            })
        })
        .collect();

    Ok(apps)
}


App uninstall

#[tauri::command]
async fn uninstall_app(package_name: String) -> Result<(), AppError> {
    let output = tokio::process::Command::new("adb")
        .args(["uninstall", &package_name])
        .output()
        .await?;

    if String::from_utf8_lossy(&output.stdout).contains("Success") {
        Ok(())
    } else {
        Err(AppError::Adb(format!("Failed to uninstall {}", package_name)))
    }
}


Clipboard sync between Android and Mac

#[tauri::command]
async fn push_clipboard_to_android(text: String) -> Result<(), AppError> {
    tokio::process::Command::new("adb")
        .args(["shell", "am", "broadcast", "-a", "clipper.set", "-e", "text", &text])
        .status()
        .await?;
    Ok(())
}

#[tauri::command]
async fn get_android_clipboard() -> Result<String, AppError> {
    let output = tokio::process::Command::new("adb")
        .args(["shell", "am", "broadcast", "-a", "clipper.get"])
        .output()
        .await?;

    // Parse broadcast result for clipboard content
    let stdout = String::from_utf8_lossy(&output.stdout);
    extract_clipboard_from_broadcast(&stdout)
}

Note: clipboard sync via ADB requires Clipper or similar app on the Android device.


Error handling for ADB not found

fn check_adb_available() -> Result<(), AppError> {
    Command::new("adb")
        .arg("version")
        .output()
        .map_err(|_| AppError::Adb(
            "ADB not found. Please install Android Platform Tools.".into()
        ))?;
    Ok(())
}

Check on launch, not on first use. Users should know immediately if ADB is missing.


TL;DR: Building ADB tools in Rust + Tauri: parse specific error codes for APK install (not just "failed"), use pm list packages -3 for third-party apps, and check ADB availability on launch. Clipboard sync needs Clipper on the Android side.


If this was useful, a ❤️ helps more than you'd think — thanks!

HiyokoKit | X → @hiyoyok