Users browsing this thread: 1 Guest(s)
z3bra
Grey Hair Nixers
Here are some updates on the topic, even though no one seemed interrested:

I gave up on OpenBSD. Getting the emulator running on Debian was painful enough, that I didn't want to fight it on OpenBSD. I found a thread stating that someone managed to get the emulator running on OpenBSD, and that has the linux compatibility mode as a hard requirement (to run ELF binaries), and that was removed from base in 6.0 (I'm running 6.7 everywhere). At this point I was about to spin up a linux VM on my OpenBSD, in order to run Android VM on it… So I decided to rent a cheap bare metal server (500Gb HDD, 4Gb Ram, Intel Avoton with VT-x support). You must take the following into account:
  • Emulator won't start if there isn't at least 2Gb of free memory
  • Emulator won't start if there is "no enough diskspace" (I think around 8Gb)
  • Running the emulator from a virtual machine means no VM acceleration available (use --no-accel), resulting in a slower VM

I slapped a Debian 10 on that VPS and installed "android-sdk" from the repo. It pulled a JDK 11 as a dependency, which seems to work correctly (despite the warning on the mautrix link). I also needed the following packages for the emulator to start (libs shipped with the emulator didn't work):
  • libopengl0
  • libegl1-mesa
  • libgl1
  • libtinfo5
  • libxdamage1

The sdk is installed to /usr/lib/android-sdk. I grabbed the CLI tools for android (not in the debian repo) from here: https://developer.android.com/studio/command-line. I unpacked it in my $HOME directory, and used the tool "sdkmanager" to install all the needed stuff to my SDK root:

Code:
# First bootstrap the cmdline tools properly
sudo ./sdkmanager --sdk_root=/usr/lib/android-sdk 'cmdline-tools;2.1'
sudo ln -s /usr/lib/android-sdk/cmdline-tools/2.1/bin/sdkmanager /usr/bin/sdkmanager
sudo ln -s /usr/lib/android-sdk/cmdline-tools/2.1/bin/avdmanager /usr/bin/avdmanager

sudo sdkmanager emulator
sudo sdkmanager platform-tools
sudo sdkmanager 'system-images;android-30;google_apis_playstore;x86_64'
sudo sdkmanager --update

sudo ln -s /usr/lib/android-sdk/emulator/emulator /usr/bin/emulator

Now that the SDK is ready, you must create and android VM, and install/configure Whatsapp on it. This MUST be done on a system with graphical interface, as you need to use the touchscreen of the device. The above steps can be used to install the Android SDK on your local machine.

Create and launch the VM:

Code:
avdmanager create avd -n whatsapp -k 'system-images;android-30;google_apis_playstore;x86_64'
emulator -avd whatsapp
[code]

Don't forget to allow the USB fingerprint key when the phone starts. You'll need it for connecting to the emulator on your server with "adb".

Then you can use the emulator to install whatever app you want, and configure it. For my needs, I installed whatsapp and configured it with my account using the v4l2loopback kernel driver to hook the device camera to a running ffmpeg recording my desktop. This is needed to scan a QR code. Whatever.

When you're done, shutdown the device, and rsync the whole ~/.android directory to your server. You should then be able to run the emulator, headless on your server:

[code]
nohup emulator -avd whatsapp -no-audio -no-window > emulator.log &
until adb shell; do sleep 1; done

To connect successfully using "adb", you need to have accepted the fingerprint key on your local computer, and use the same ~/.android/adbkey file on your server. As "adb" is required to push a new key, you need to have it configured BEFORE you need to use it on the server.

It is possible that your device doesn't have internet access after boot. That was my case, and it is due to the wlan0 interface being down. You can enable it with:

Code:
adb shell "svc wifi enable"

You need to wait for the device to finish booting before doing that, or it will complain that the "wifi" service doesn't exist. It took so freaking long on the qemu-based VPS I used first that I though it was an issue with the emulator-within-virtualmachine, and switched to a baremetal server. Turns out after a loooong time (few hours?), I tried to enable it on the qemu-based one, and it worked. Just took really long because there was no hardware acceleration.

I now have a fully running android VM on my server ! I can use the adb shell to start applications, and do whatever is possible from the adb shell.

Happy hacking !


Messages In This Thread
Android server edition - by z3bra - 30-06-2020, 10:55 AM
RE: Android server edition - by z3bra - 06-07-2020, 07:18 AM
RE: Android server edition - by octahedral - 06-07-2020, 07:14 PM
RE: Android server edition - by z3bra - 07-07-2020, 04:29 AM
RE: Android server edition - by jkl - 07-07-2020, 01:31 PM
RE: Android server edition - by wolf - 07-07-2020, 10:14 PM
RE: Android server edition - by z3bra - 08-07-2020, 04:46 AM
RE: Android server edition - by jkl - 08-07-2020, 05:02 AM
RE: Android server edition - by z3bra - 09-07-2020, 05:32 AM