---
name: android_apk_install
kind: function
lang: bash
domain: infra
version: "1.0.0"
purity: impure
signature: "android_apk_install([--serial S], apk_path: string, package_name?: string, activity_name?: string) -> void"
description: "Instala APK en device/emulador via adb y opcionalmente lanza la app. Multi-emulator via --serial."
tags: [android, adb, apk, wsl]
params:
  - name: "--serial <S>"
    desc: "Optional target device/emulator serial. Default: first device detected by adb_pick_serial."
  - name: apk_path
    desc: "WSL path to APK file"
  - name: package_name
    desc: "Optional app package id (e.g. com.fnregistry.voiceguide). Launches the app if provided."
  - name: activity_name
    desc: "Optional activity (.MainActivity or fully qualified). Only used with package_name. If omitted, launches via monkey LAUNCHER intent."
output: "Stdout con pasos. Exit 0 = install + launch OK. Exit !=0 si install fallo o APK no encontrado."
uses_functions: ["adb_wsl_bash_infra"]
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "bash/functions/infra/android_apk_install.sh"
---

## Ejemplo

```bash
# Solo instalar
android_apk_install /home/lucas/builds/app-debug.apk

# Instalar y lanzar con activity explícita
android_apk_install /home/lucas/builds/app-debug.apk com.fnregistry.voiceguide .MainActivity

# Instalar y lanzar sin activity (usa monkey LAUNCHER)
android_apk_install /home/lucas/builds/app-debug.apk com.fnregistry.voiceguide

# Llamada directa desde shell (no sourced)
bash bash/functions/infra/android_apk_install.sh /path/to/app.apk com.example.app .MainActivity

# Override ADB path
ADB=/custom/path/adb.exe bash bash/functions/infra/android_apk_install.sh /path/to/app.apk
```

## Notas

- Requiere WSL2 con `adb.exe` Windows accesible. El path por defecto es
  `/mnt/c/Users/lucas/AppData/Local/Android/Sdk/platform-tools/adb.exe`.
  Se puede sobreescribir con `ADB=...` o `ANDROID_SDK_WIN=<sdk_root>` antes
  de invocar.
- `wslpath` se usa para convertir el path WSL a formato Windows (`C:\...`).
  Si no está disponible (entorno no-WSL), se usa el path tal cual.
- La instalación usa `adb install -r` (reinstala si ya existe).
- Si `package_name` se da sin `activity_name`, la app se lanza via
  `adb shell monkey -p <pkg> -c android.intent.category.LAUNCHER 1`,
  que es equivalente a pulsar el icono del launcher.
- El script se puede sourcear (para usar la función en otros scripts) o
  ejecutar directamente. Cuando se ejecuta directamente, delega en
  `android_apk_install "$@"`.
