ConstraintLayout

Follow me on GitHub

Gradle Integration

Wolfram Rittmeyer

v3.0 All of the examples in this article have been created using Android Studio v3.0.
You may see differences if you are using a different version.

v1.0.2 or 1.1.0 All of the examples in this article have been created using ConstraintLayout v1.0.2 or 1.1.0.
You may see differences if you are using a different version.

Top level build configuration

You can add ConstraintLayout as you do with other dependencies: by adding it to your gradle build.xml file.

Since ConstaintLayout is part of the Support Library family provided by Google, you have to use the Google Maven repository.

Most likely your project is using other parts of the Support Library family anyway, but to be sure, here’s how to configure your top level build file to use the Google repository:

buildscript {
  repositories {
    google()
    jcenter()
  }

  dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
  }
}

allprojects {
  repositories {
    google()
    jcenter()
  }
}

Module specific configuration

With this configuration in place, you simply add the version of ConstraintLayout you want to the module specific gradle file (usually within the app module):

dependencies {
  // other libs...
  implementation 'com.android.support.constraint:constraint-layout:1.1.0'
  // other libs...
}

Versions

You should be using ConstraintLayout 1.1.0 or newer - please refer to Google’s Maven repository for the most up-to-date information.

Features of the 1.1 branch that are missing in the 1.0 release:

Android Studio’s Layout Editor

Newer features of the ConstraintLayout are best supported in newer versions of Android Studio. While the 3.0.x versions are stable, they might not support all features of the latest betas. On the other hand the 3.1 and 3.2 versions are in active development. They are bound to contain bugs and might not properly support all of the older features.

If you use XML anyway, the specific version of Android Studio is of less importance.