### Install

Instructions taken from [here](https://github.com/google-research/android_world).
Use standard install.

1. Set up the Android Emulator
   1. Download Android Studio [here](https://developer.android.com/studio?gad_source=1&gclid=Cj0KCQjw3ZayBhDRARIsAPWzx8oLcadBD0vAq8xmUutaunLGSzhgEtLz4xVZ_SpV4G0xJazS7LxQkDsaAuveEALw_wcB&gclsrc=aw.ds)
   2. Create an Android Virtual Device (AVD) by following these instructions. For hardware select **Pixel 6**, for System Image select **Tiramisu, API Level 33**, and choose AVD name as **AndroidWorldAvd**. [Watch the setup video.](https://github.com/google-research/android_world/assets/162379927/efc33980-8b36-44be-bb2b-a92d4c334a50)

2. Launch the Android Emulator from the command line

Launch the emulator from the command line, not using the Android Studio UI, with the `-grpc 8554` flag which is needed communication with accessibility forwarding app.

```bash
# Typically it's located in ~/Android/Sdk/emulator/emulator or
# ~/Library/Android/sdk/emulator/emulator
EMULATOR_NAME=AndroidWorldAvd # From previous step
~/Library/Android/sdk/emulator/emulator -avd $EMULATOR_NAME -no-snapshot -grpc 8554
```

3. [Optional] It's recommended to use `conda`, which you can download [here](https://docs.anaconda.com/free/miniconda/miniconda-install/).

```
conda create -n android_world python=3.11.8
conda activate android_world
```

4. Install the latest [AndroidEnv](https://github.com/google-deepmind/android_env):

```python
git clone https://github.com/google-deepmind/android_env.git
cd android_env
python setup.py install
```

5. Install AndroidWorld. *Note: Python 3.11 or above is required.*


```python
git clone https://github.com/google-research/android_world.git
cd ./android_world
pip install -r requirements.txt
python setup.py install
```

6. Install `ffmpeg`, if not already installed.

```bash
# Linux (Ubuntu/Debian)
# sudo apt update && sudo apt install ffmpeg

# macOS
brew install ffmpeg
```

### Known Issues

**Protobuf Version Compatibility**

While running `android_world`, if you encounter an error like:

```bash
ImportError: cannot import name 'runtime_version' from 'google.protobuf'
```

Fix by installing a specific protobuf version:

```bash
pip install protobuf==5.29.0
```

NOTES from Aymeric:
above gave me conflicts, I had to de install the conflicting google generative ai package, then reinstall protobuf, then reinstall the generative ai package.
ALSO, NEED TO COMMENT OUT THE LINE THAT CONTAINS THIS, ELSE SOME `rm` command fails:
```python
["shell", "rm", f"{device_constants.EMULATOR_DATA}/*"],
```

## Running the agent
```bash
EMULATOR_NAME=AndroidWorldAvd # From installation step
~/Library/Android/sdk/emulator/emulator -avd $EMULATOR_NAME -no-snapshot -grpc 8554
```
