This is a proof of concept I just got working. It’s not complete and I could use the feedback - maybe there are better approaches or someone can contribute improvements.
This is all tested on a physical Linux server. I used a second nic to add local LAN access.
The Android apps I needed all required some kind of local/broadcast access. If you’re 100% sure your app is cloud based you could skip the local lan parts.
Rationale: I have devices with broken integrations or have other issues, incomplete integrations etc.
Some of this can help with reverse engineering/debugging as well. Ideally vendors would have open APIs and documentation but that’s not always the case.
- Install an Android emulator. I tried several but I settled on redroid as I already use Docker and it’s well suited to running on a server. It also supports Arm apks which is great because I found a lot of IoT/automation apps do not support x86_64.
I tried:
- Anbox - old/unmaintained, works with Intel apks only. GUI based - not great for headless
- Waydroid - better support, including Arm but needs Wayland/GUI - not great for headless
- Anbox Cloud - interesting but complicated and doesn’t support Arm out of the box. “Free” for personal use/Ubuntu pro. Does anyone know if Amzon Luna is using this? Headless/web based
- Setup bridge networking for local lan access.
- Docker needs a networking plugin installed.
- Docker/android networking was a bit trickier but it’s working with steps here
- Anbox/Waydroid: you can add the second nic to the anbox0 or waydroid0 bridge as with Docker
- Test Android
- Docker/local LAN it will get its own up address you can check with
docker container inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $id
- Docker:
connect ipaddress:5555
should connect - Check networking with
adb shell
- Install and test your apps/apks
- scrcpy is a must have for testing Docker android since there’s no other gui. Great for other things like viewing Android/Amazon tv boxes too.
- Install Maestro mobile UI framework
- Maestro was really straightforward to get up and running with instructions here.
- Maestro needs open-jdk11
maestro studio
should start up and detect the device if adb is working.- Browse to http://localhost:9999
- Click and record/run actions. You can export these to a yaml flow
- Create a Home Assistant Dashboard and Card
- Default aspect ratio 50% is way too small so increase it! I gave it it’s own dashboard
- You should be able to see and control the Android device
- Maestro studio is a bit limited but you can select actions and run them
maestro studio
uses http so I had to browse to the http:// port of my homeassistant for this to work
- TODO
- there’s a lot left to package this up cleanly but it’s a start
- I need to get maestro in its own container and setup through ha-proxy so https will work
- maestro studio is an easy way to get started but the maestro cli could be tied in to homeassisitant. Maybe appium.io is a better approach if you really want to roll up your sleeves.
- Hopefully there’s a way to look at status/results and not just playback buttons
- SECURITY: the emulator can be booted without root access and can probably run the Docker container with fewer privileges. Maybe more can be tightened up.