Skip to content

Instantly share code, notes, and snippets.

@technosophos
Last active October 13, 2020 00:01
Show Gist options
  • Save technosophos/f16bfe59570aeccab75b86284e24d764 to your computer and use it in GitHub Desktop.
Save technosophos/f16bfe59570aeccab75b86284e24d764 to your computer and use it in GitHub Desktop.
Installing a VS Code-based development environment for FTC on Linux

Installing a Development Environment for FTC on Linux with VS Code

This documents my attempts to get the First Tech Challenge (FTC) base code running on Linux using VS Code instead of Android Studio. Android Studio is a little too slow and hefty for my liking.

Prerequisites

I am running Ubuntu 18.04. Package names and installation methods will vary on other platforms.

Install JDK

Ubuntu provides OpenJDK implementations in the main repository.

$ apt-cache search openjdk
default-jdk - Standard Java or Java compatible Development Kit
default-jdk-doc - Standard Java or Java compatible Development Kit (documentation)
default-jdk-headless - Standard Java or Java compatible Development Kit (headless)
default-jre - Standard Java or Java compatible Runtime
default-jre-headless - Standard Java or Java compatible Runtime (headless)
openjdk-11-dbg - Java runtime based on OpenJDK (debugging symbols)
openjdk-11-doc - OpenJDK Development Kit (JDK) documentation
...
$ sudo apt-get install openjdk-8-jdk

NOTE: At the time of this writing, Android Studio does not work with JDKs newer than 8. Otherwise we could install default-jdk

Install Android Tools

Ubuntu provides a package of the Android developer tools:

$ apt-cache show android-sdk-platform-tools
Package: android-sdk-platform-tools
Architecture: amd64
Version: 27.0.0+10~18.04.2
Priority: optional
Section: universe/metapackages
Source: android-sdk-meta (25
...
$ sudo apt-get install android-sdk-platform-tools android-sdk

This is huge, and may take a while.

When this all is done, you should be able to execute the following commands without error:

$ javac -version
javac 11.0.4
$ adb --version
Android Debug Bridge version 1.0.39
Version 1:8.1.0+r23-5~18.04
Installed as /usr/lib/android-sdk/platform-tools/adb

The android-sdk package will create $HOME/Android/Sdk for you. Important tools like sdkmanager are in that directory.

Run sdkmanager --licenses

Once android-sdk is installed, you need to do this exactly:

$ cd $HOME/Android/Sdk/tools
$ bin/sdkmanager --licenses

Then read and accept all of the licenses there. It will create a directory called $HOME/Android/Sdk/licenses with your signed licenses. In some cases, you may need to cp -a $HOME/Android/Sdk/licenses /usr/share/libandroid-*/licenses.

Install VS Code

Go to the VS Code site and download and install the environment. If it works, you should be able to run code --version without error.

Install the GitHub Project

Follow the direction on the official FTC GitHub site to get the FTC libraries. You may need a GitHub account to do this.

Open the ftc_app in VS Code

You can open VS Code and navigate there, or do this from the commandline:

$ cd LOCATION_OF_FTC_APP
$ code -n .

Install the Java Tools for VS Code

If you open a *.java file (any Java file), VS Code will prompt you to install the bundle of Java tools. I recommend doing this. It will turn VS Code into an IDE for Java.

Set up Android SDK

Inside of the ftc_app directory, create a file called local.properties and add an sdk.dir= parameter:

sdk.dir=sdk.dir=$HOME/Android/Sdk

NOTE: Replace $HOME with your home directory (e.g. /home/technosophos).

This tells Gradle where to find your Android SDK. (Check /usr/share for a version of libandroid. It might be different than the one above.)

Now open a terminal in VS Code and run ./gradlew. This should build your code. If it complains about licenses, re-read the section about sdkmanager above. If it complains about missing classes, you have either gotten the value of sdk.dir incorrect, or you are running a JDK newer than version 8.

Other Tips on Java

In Ubuntu, use update-alternatives to select between versions of Java:

$ update-alternatives --list java
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

The update-alternatives command is well documented. You need to use update-alternatives --set java /path/to/jdk8/jre/java and update-alternatives --set javac /path/to/jdk8/javac, replacing those paths with the ones output from update-alternatives --list for java and javac.

Useful References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment