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.
I am running Ubuntu 18.04. Package names and installation methods will vary on other platforms.
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
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.
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
.
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.
Follow the direction on the official FTC GitHub site to get the FTC libraries. You may need a GitHub account to do this.
You can open VS Code and navigate there, or do this from the commandline:
$ cd LOCATION_OF_FTC_APP
$ code -n .
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.
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.
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
.
- A VS Code specific version of an older FTC app: https://github.com/cookthebook/ftc_app/