FTC > General > Programming
Developing with Android Studio
Contributors:
Hamid Hussain
Hamid Hussain
When starting out with FTC programming, many programmers choose to use OnBotJava, a text editor built into the FTC Robot Controller and accessible through a robot's web interface. Android Studio is an IDE (Integrated Development Environment) which runs on your computer and has many more features such as Git integration, Android-specific tools, and Code Completion, and is much more useful for FTC programming.
To install Android Studio, go to the Android Studio Downloads page at https://developer.android.com/studio. From there, click on the large download button to download the latest version of Android Studio for your operating system.
After agreeing to the Terms and Conditions, this will download an EXE, DMG, or TAR.GZ file to your computer based on your operating system. To install Android Studio, use this file as you normally would - on Windows, for example, double-click to execute the file and follow the instructions presented by the installer window.
Here are a few example commands for different package managers that you can use to install Android Studio. If your package manager is not on this list, you may be able to use its built-in search function or search online.
Winget: winget install Google.AndroidStudio
Brew: brew install --cask android-studio
Snap: sudo snap install android-studio
This article assumes you already have Git set up on your computer, including authentication for your GitHub account. If you haven't set up a GitHub account and/or don't have Git set up, follow the instructions in the articles linked here.
To begin, in a folder that you designate for robotics purposes, run the following Git Bash command in a terminal.
git clone https://github.com/FIRST-Tech-Challenge/FtcRobotController.git
This will clone the FTC SDK into a new folder. The command output and new folder should look like this:
Next, change your terminal directory into this new folder using the command
cd FTCRobotController
Then, use the following command to disconnect the folder from the official FTC remote repository.
git remote remove origin
Then, use this command to link the files to your own GitHub repository, making sure to copy the link to it using the green "Code" button.
git remote add origin <your github link>
Finally, use this command to push all the files to your remote repository.
git push origin HEAD
Now, your GitHub repository should look similar to that of our other FTC Robots:
In order to start developing, you need to open the folder in Android Studio. To do this, open Android Studio and click the "Open" button. Then select the folder you cloned. You should rename this folder to the name of your GitHub repo to differentiate between different projects.
The FTC SDK is a large Android project that contains files that create the entire Robot Controller android package. This means it is much more complex than the file structure of OnBotJava, which is a simplified view. In the FTC SDK, the TeamCode folder is located at
TeamCode\src\main\java\org\firstinspires\ftc\teamcode
which looks like this in Android Studio.
In order to create a Java file, right-click the teamcode folder and select New > Java Class.
If you are used to using an OpMode Template to start your project, all of the samples can be found in
FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples
which looks like this in Android Studio.
After you are done with your robot code, you can connect a Control Hub or other Android Device to the computer you are using through a USB-C cable. After that, click the Gradle icon on the right side of the window and select the "InstallRelease" task under the main "Tasks" folder. This completes all tasks required to build the FTC Robot Controller package and upload your code to the robot.
To push your changes to GitHub, use the built-in terminal or an external terminal and run the following commands from the project folder (replace the part in square brackets).
git commit -a -m "[A commit message detailing your changes]"
git push origin HEAD
Sometimes, during a season, updates will be published to the FTCRobotController repo. To download these updates to your own projects, follow these steps.
First, in the terminal, type this command:
git remote add upstream https://github.com/FIRST-Tech-Challenge/FTCRobotController.git/
This will add the master FTCRobotController remote repo back to your project under the remote name "upstream".
Then, in Android Studio, click the source control icon and then click the dropdown next to the "upstream" remote, then right click the master branch.
This will bring up a context menu (not shown in screenshot), from which you should select the option "Pull into 'main' using merge". This may bring up a secondary menu, asking you to resolve some merge conflicts. Usually, keeping your changes is fine.