Adding the Lifecycle Components

You will need a runtime dependency and an annotation processor, akin to how Room is set up:

dependencies {
  implementation "com.android.support:recyclerview-v7:28.0.0"
  implementation "com.android.support:support-fragment:28.0.0"
  implementation "android.arch.lifecycle:runtime:1.1.1"
  implementation "android.arch.lifecycle:common-java8:1.1.1"
  implementation "android.arch.core:runtime:1.1.1"
}

android {
    compileSdkVersion 28
    

  defaultConfig {
      minSdkVersion 21
      targetSdkVersion 28
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

However, making sense of the artifact versions — particularly when transitive dependencies come into play — will be difficult.

If your project directly or indirectly depends upon support-compat version 26.1.0 or higher, support-compat has a dependency on android.arch.lifecycle:runtime, for some version of that artifact. What version that is will depend on the version of support-compat:

Support Library Version android.arch.lifecycle:runtime Version
28.0.0 1.1.1
27.1.1 1.1.1
27.0.2 1.0.3
26.1.0 1.0.0

In addition, we have a dependency on android.arch.lifecycle:common-java8, which provides better Java 8 support for the lifecycle system.

How these versions will work out in the future is anyone’s guess right now.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.