8

I am trying to add lifecycle:extensions to my project but i can not make it work . Each time it shows error .

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve android.arch.lifecycle:extensions:1.1.0.

I have already read several threads but could not make it work by the answers given there. Project level gradle is:

buildscript {
repositories {
   google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.2'
}
}

allprojects {
repositories {
    google()
    maven { url 'https://maven.google.com' }
    jcenter()
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

And build.gradle is :

implementation "android.arch.lifecycle:extensions:1.1.0"
annotationProcessor "android.arch.lifecycle:compiler:1.1.0"

How can i make it work? I am on Android Studio 3.1.2 . I also tried to import some github samples but same error occurred each time . Now its been 7 hours i have been busting my head on this.

Diaz diaz
  • 284
  • 1
  • 7
  • 21

4 Answers4

3

You already added google() in the Build.gradle so, try adding the latest version:

implementation "android.arch.lifecycle:extensions:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"

Also, go to:

File -> Settings -> Build, Execution, Deployment -> Build tools -> Gradle

And uncheck the option if it is checked to download from repository.


In case it didn't help, updating gradle to the latest version will help:

dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'
}
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
  • 3
    **What a HORROR** . How the hell changing version worked ? Is that mean `1.1.0` is not available on maven. I changed it to `1.1.1` just like you said and it worked . Can i have some explanation on this for future . – Diaz diaz Sep 13 '18 at 12:23
  • That's a good question too. The `1.1.0` version might not be available with the current Gradle versions so, as a experience, updating to the latest version will work at this point. – ʍѳђઽ૯ท Sep 13 '18 at 12:28
2

I faced and fortunately solved this problem.

The solution is: You should open the firebase_database flutter plugin's build.gradle (project root >> Flutter Plugins >> firebase_database-3.1.0 >> android >> build.gradle) and you should change the last same lines according to the following:

from: `

if (!containsEmbeddingDependencies) {
  android {
    dependencies {
      def lifecycle_version = "1.1.1"
      compileOnly "android.arch.lifecycle:runtime:$lifecycle_version"
      compileOnly "android.arch.lifecycle:common:$lifecycle_version"
      compileOnly "android.arch.lifecycle:common-java8:$lifecycle_version"
    }
  }
}

`

to: `

if (!containsEmbeddingDependencies) {
  android {
    dependencies {
      def lifecycle_version = "2.1.0"
      api "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
      api "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
    }
  }
}

`

I found this solution according to a TODO in the plugin's code and it refers to a github issue: https://gist.github.com/blasten/78e97b1d97a736d7e8dcc3f520cea3f0

It works perfectly for me and solves the exact same issue above.

Cheers

0

I add these:

 implementation 'androidx.legacy:legacy-support-v4:1.0.0'
 implementation 'androidx.media:media:1.1.0'

some times you can new a project ,then compare it.

tf z
  • 21
  • 1
0

You're using androidx artifacts, therefore the classes that used to be in android.arch.lifecycle are now in androidx.lifecycle as per the Migrating to AndroidX documentation.

Ashish Chaugule
  • 1,526
  • 11
  • 9