├── README.md └── ipad.jpg /README.md: -------------------------------------------------------------------------------- 1 | # JetBrains Projector with Android Studio 2 | 3 | Guide to setup JetBrains Projector and access Android Studio from any device. 4 | 5 | [Blog post](https://joenrv.medium.com/how-to-run-android-studio-on-any-device-with-jetbrains-projector-3d9d23a8c179) 6 | 7 | ![Android Studio on iPad Pro](ipad.jpg) 8 | *Android Studio on an iPad Pro* 9 | 10 | ### Step 1: Spin up a Linux server 11 | 12 | This guide will explain how to get a virtual machine setup with Amazon AWS, but you can choose any other provider like Google Cloud or Microsoft Azure, or even a machine on your local network. 13 | 14 | 1. Make a [AWS account](https://aws.amazon.com/free/) and login 15 | 2. Go to the EC2 section and select create a new Instance 16 | 3. Search for "Debian" in the AWS Marketplace and choose the latest Debian distribution (Debian 10 Buster at the time of writing) 17 | 4. Pick the instance type, I suggest one with at least 8Gb RAM, preferrably more 18 | 5. Click next until you get to storage, and choose how much storage you need. I suggest at least 20Gb (you can always expand this later) 19 | 6. Click next until the security section, you need to add a new rule to be able to access the port that Projector will use 20 | * Add a new custom TCP rule with port 8888 (or any port you like, will be useful in the next step) 21 | * If you want to secure access, you can choose to only allow connections only from your own IP adress (recommended): Source > My Ip 22 | 7. Choose or create a private key to access the instance and start it 23 | 8. Write down the IP addresss (ipv4) shown in the EC2 console 24 | 25 | ### Step 2: Connect to your remote server via SSH 26 | 27 | 1. To make it easy to connect to your instance, create a new file ~/.ssh/config (if it doesn't exist already) 28 | 2. Add a new host to your ~/.ssh/config: 29 | ``` 30 | Host {REMOTE_MACHINE_ALIAS} 31 | User {REMOTE_MACHINE_USERNAME} 32 | HostName {REMOTE_MACHINE_IP_OR_HOSTNAME} 33 | Port 22 34 | IdentityFile ~/.ssh/{SSH_KEY_NAME} 35 | PreferredAuthentications publickey 36 | ControlMaster auto 37 | ControlPath /tmp/%r@%h:%p 38 | ControlPersist 1h 39 | ``` 40 | * `Host` - Choose an alias like `remote-builder` or anything you like 41 | * `User` - By default, the username for a Debian server is `admin` 42 | * `Hostname` - the IP address of your EC2 instance 43 | * `IdentityFile` - the path to your private key file downloaded when creating the EC2 instance 44 | 45 | 3. Now you can connect to your machine easily like this 46 | 47 | ``` 48 | $ ssh remote-builder 49 | ``` 50 | 4. Once connected, you can now begin installing things on your remote server 51 | 52 | Note: when you're done, remember to stop your AWS instance to stop being charged! 53 | 54 | ### Step 3: Install Projector and Android Studio on the remote server 55 | 56 | 1. To install Projector (and dependencies), run the following commands: 57 | ``` 58 | $ sudo apt-get update 59 | $ sudo apt install python3 python3-pip 60 | $ sudo apt install libxext6 libxrender1 libxtst6 libfreetype6 libxi6 61 | $ pip3 install projector-installer 62 | ``` 63 | 2. Projector is now installed, you can see all options by running 64 | ``` 65 | projector --help 66 | ``` 67 | 3. At this point, you could run one of the pre-configured IDEs like IntelliJ and start using it, but to run Android Studio, you need to install it separately. 68 | 4. Download the latest Android Studio Arctic Fox or above (Arctic Fox is the minimum version that works with Projector) 69 | * Find the latest download URL for linux from https://developer.android.com/studio/archive. At the time of writing, the latest version is Artic Fox Patch 2 70 | * Download it to your remote server in your home directory with curl: 71 | 72 | ``` 73 | $ curl -L --output android-studio.tar.gz https://redirector.gvt1.com/edgedl/android/studio/ide-zips/2020.3.1.24/android-studio-2020.3.1.24-linux.tar.gz 74 | ``` 75 | * Unzip the downloaded archive: 76 | 77 | ``` 78 | $ tar -xvf android-studio.tar.gz 79 | ``` 80 | 5. You now have Android Studio installed, all that is left is to configure Projector, making sure to select the port that was chosen as the custom TCP rule for the VM (step 1.6) - here we're using port 8888. When asked to use a secure connection, I recommend saying yes to ensure copy pasting functionality works properly. 81 | ``` 82 | $ projector config add 83 | Enter a new configuration name: AndroidStudio 84 | Do you want to choose a Projector-installed IDE? [y/n]: n 85 | Enter the path to IDE: /path/to/your/android-studio 86 | Enter a desired Projector port (press ENTER for default) [10005]: 8888 87 | Use secure connection (this option requires installing a projector's certificate to browser)? [y/n]: y 88 | ``` 89 | 6. This will start Android Studio with Projector on port 8888. Next time you want to start it, you can just run: 90 | 91 | ``` 92 | $ projector run AndroidStudio 93 | ``` 94 | 95 | ### Step 4: Access Android Studio from a Browser 96 | 97 | 1. On your local machine, start a browser and go to `http://:8888` 98 | 2. If you've chosen "use secure connection" you'll get a warning saying the certificate is unknown, select proceed anyways 99 | 3. Enjoy your remote Android Studio! 100 | 101 | ### Optional: Setup ADB to deploy to / debug a local device 102 | 103 | 1. You need to have the same version of adb on the remote and local machine 104 | ``` 105 | $ adb -- version 106 | Android Debug Bridge version 1.0.41 107 | Version 30.0.4-6686687 108 | ``` 109 | 2. Kill adb on both local and remote machines if it was already running 110 | ``` 111 | $ adb kill-server 112 | ``` 113 | 3. On the local machine, with an Android device connected, run: 114 | ``` 115 | $ adb devices 116 | List of devices attached 117 | ABCDEF12345 118 | $ ssh -R 5037:localhost:5037 remote-builder 119 | ``` 120 | 4. This will connect to your instance with port forwarding enabled. Now check that the device is visible on the remote machine: 121 | ``` 122 | $ adb devices 123 | List of devices attached 124 | ABCDEF12345 125 | ``` 126 | 5. That's it! Both machines can now run adb commands and everything will be redirected to the local phone. 127 | 6. To always connect to your instance with adb port forwarding (port 5037 by default), you can add the following line to your `~/.ssh/confg`: 128 | ``` 129 | RemoteForward 5037 localhost:5037 130 | ``` 131 | ### Script to facilitate the entire workflow 132 | 133 | This is the home made script I use. It takes care of starting my EC2 instance which I gave a static IP adress to, starting Projector in a tab-less Chrome and stopping the EC2 instance when I exit Chrome. Put this in a bash script, like `work.bash` and run it. The script uses the aws CLI, which you will have to setup beforehand ([documentation](https://aws.amazon.com/cli/)). Make sure to replace the placeholder instance ids with your own. 134 | 135 | ``` 136 | #!/bin/bash 137 | INSTANCE_ID= 138 | STATIC_IP= 139 | PORT=8888 140 | 141 | echo "Starting Server..." 142 | aws ec2 start-instances --instance-ids $INSTANCE_ID 143 | aws ec2 wait instance-running --instance-ids $INSTANCE_ID 144 | echo "Server Started" 145 | adb devices 146 | ssh -o 'ConnectionAttempts 10' remote-builder "/home/admin/.local/bin/projector run AndroidStudio" & 147 | sleep 5 148 | echo "Projector started, opening browser..." 149 | open -W -na "Google Chrome" --args --new-window --app="https://$STATIC_IP:8888/?host=$STATIC_IP&port=$PORT" 150 | echo "Stopping Server..." 151 | aws ec2 stop-instances --instance-ids $INSTANCE_ID 152 | aws ec2 wait instance-stopped --instance-ids $INSTANCE_ID 153 | echo "Done" 154 | ``` 155 | 156 | If you don't want to give a static IP address to your EC2 instance, you can get the generated IP automatically with the aws CLI, which removes the need for having a `.ssh/config` file altogether. This is what the modified script looks like (Thanks @Clement-Jean for the tip!): 157 | 158 | ``` 159 | #!/bin/bash 160 | 161 | INSTANCE_ID= 162 | PORT=8888 163 | USER=admin 164 | REGION= 165 | 166 | echo "Starting Server..." 167 | aws ec2 start-instances --instance-ids $INSTANCE_ID 168 | aws ec2 wait instance-running --instance-ids $INSTANCE_ID 169 | echo "Server Started" 170 | IP=`aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[*].Instances[*].PublicIpAddress' --output text` 171 | EC2_IP=`echo $IP | sed 's/\./-/g'` 172 | 173 | adb devices 174 | ssh -o 'ConnectionAttempts 10' -i $USER@ec2-$EC2_IP.$REGION.compute.amazonaws.com "/home/$USER/.local/bin/projector run AndroidStudio" & 175 | sleep 5 176 | echo "Projector started, opening browser..." 177 | open -W -na "Google Chrome" --args --new-window --app="https://$IP:8888/?host=$IP&port=$PORT" 178 | aws ec2 stop-instances --instance-ids $INSTANCE_ID 179 | aws ec2 wait instance-stopped --instance-ids $INSTANCE_ID 180 | echo "Done" 181 | ``` 182 | 183 | ### Useful links and other installation methods 184 | 185 | [Main Projector README](https://github.com/JetBrains/projector-server/blob/master/README-JETBRAINS.md) 186 | 187 | [Projector Docker Image](https://github.com/JetBrains/projector-docker) 188 | 189 | [Projector Installer Repo](https://github.com/JetBrains/projector-installer) 190 | 191 | [Projecter Server Repo](https://github.com/JetBrains/projector-server/blob/master/docs/Projector.md) 192 | 193 | -------------------------------------------------------------------------------- /ipad.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joaquim-verges/ProjectorAndroidStudio/8cbb61f94b7009caa2bf722ce471af67f7083f87/ipad.jpg --------------------------------------------------------------------------------