Source code setup

This section describes how to setup your Git repository with an empty, "starting" project.

Tip

Before you can proceed you should have completed the following:

Setup your Source Code

Step 1. Getting a working copy of your Git repository

First, you need to git clone your GitLab repository to your local machine so that you have a working copy.

Open the web page for your GitLab project. Click on the Code button, and copy the URL from Clone with HTTPS.

In a terminal, on your computer, cd to the location where you want to keep your source code. git clone the URL.

$ git clone https://git.uwaterloo.ca/cs346/public/mm.git

This would produce a folder named mm that contains the contents of my Git repository.

Step 2. Create an empty project.

You will want to create a project directly in your Git working copy from the previous step.

IntelliJ IDEA and Android Studio both fully support Gradle, and we can create a new project directly in the IDE.

IntelliJ IDEA (Desktop)

From the Splash screen, select New Project. New Project Wizard

In the project wizard, choose New Project and supply the following project parameters.

  • Kotlin as your language (from the list on the left).
  • Name is the name of the folder that will contain your source code. e.g., source.
  • Location is the location of your working copy (from Step 1 above).
  • Gradle for your build system
  • JDK should point to your JDK installation (see toolchain).
  • Gradle DSL should be Kotlin as well.

Click Create to proceed. If successful, IntelliJ IDEA will open into the main window to an empty project.

Empty Project Window

You should be able to click the Run button in the toolbar to execute it.

Android Studio (Android)

From the Splash screen, select New Project.

New Project Wizard

Select Empty Activity and Next. A second screen will prompt you for project parameters.

New Project Wizard

  • Name: Your application name
  • Package name: A unique package name.
  • Save location: Your working copy location.
  • Minimum SDK: API 26 or later.
  • Build configuration language: Kotlin DSL.

Click Finish and your project should be created.

You will need to add an Android Virtual Device for testing:

  • Tools > Device Manager
  • +, Create Virtual Deviceand walk through the wizard to add an emulated device for testing.

Step 3. Add a gitignore file

You should probably add a .gitignore file to the top level of your project, specifying which files to NOT include in your repository.

Typically this would be a list of temporary build directories of any local configuration files. For example.

$ cat .gitignore
build/
out/
*.class
*.tmp
.DS_Store
.idea

Step 4. Push changes to the repository

Once you have confirmed that your project is working, you can commit and push the changes.

$ git add *
$ git commit -m "Initial commit"
$ git push

Your teammates should now be able to git pull to fetch your changes!

IntelliJ has a number of windows that it will display by default. You can toggle project windows.

  • Project: a list of all files (Cmd+1).
  • Structure: methods and properties of the current open class/source file (Cmd+7).
  • Source: the current source files (no hotkey).
  • Git: Git status and log (Cmd+9) - not shown.
  • Gradle: tasks that are available to run (no hotkey) - not shown.

Running Sample Code

We maintain a public Git repository of the source code shown in lectures. To get a copy, git clone the repository URL. This command, for instance, would create a copy of the course materials in a directory named cs346.

$ git clone https://git.uwaterloo.ca/cs346/public/ cs346

The slides folder contains sample code to accompany some of the slide decks. You can build and execute these projects directly in IntelliJ:

  • File -> Open and navigate to the top-level directory containing the build.gradle.kts file. Do NOT open a specific file, just the directory. Click Ok.
  • Click on the Run button in either IntelliJ or Android Studio to run the project.

IntelliJ with Gradle window open

Further Help

There are many excellent online resources for using IntelliJ. I’d suggest starting with the JetBrains IntelliJ Documentation and online help.