Error:Program type already present: android.arch.lifecycle.LiveData

落花浮王杯 提交于 2019-11-27 22:44:19

Apparently, this is intended behavior:

com.firebaseui:firebase-ui-firestore:3.1.0 depends on android.arch.lifecycle:extensions:1.0.0-beta1. Switching to version 3.2.2 fixes the issue by using the Lifecycle 1.1 libraries that Support Library 27.1.0 are built upon. - Issue Tracker

For me, removing the firebase-ui dependencies solved the issue since I wasn't even using the library in the first place.

I had the very same problem today when I raised the support library version.

Try to replace all '27.1.0' with '27.0.2'


Later on I did manage to remove the error by upgrading other libraries as well. THis is my current working state: root gradle:

buildscript {
    ext.kotlin_version = '1.2.21'
    ext.support_version = '27.1.0'
    ext.anko_version = '0.10.4'
    ext.android_plugin_version = '3.0.1'
    ext.google_services_version = '11.8.0'

    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"

        classpath 'com.android.tools.build:gradle:3.1.0-beta4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

////////////////// app gradle libraries:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
        transitive = true
    }

    // kotlin:
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation "org.jetbrains.anko:anko-common:$anko_version"
    implementation "org.jetbrains.anko:anko-commons:$anko_version"
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.3'

    // support libraries:
    implementation "com.android.support:recyclerview-v7:$support_version"
    implementation "com.android.support:support-v4:$support_version"
    implementation "com.android.support:design:$support_version"
    implementation "com.android.support:appcompat-v7:$support_version"
    implementation "com.android.support:cardview-v7:$support_version"
    implementation "com.android.support:support-vector-drawable:$support_version"

    // misc:
    implementation 'com.github.d-max:spots-dialog:0.7@aar'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta5'
    implementation 'com.backendless:backendless:4.4.0'
    implementation 'io.nlopez.smartlocation:library:3.3.3'

    // Google services:
    implementation "com.google.firebase:firebase-core:$google_services_version"
    implementation "com.google.firebase:firebase-auth:$google_services_version"
    implementation 'com.firebaseui:firebase-ui-auth:3.2.2'

    implementation "com.google.android.gms:play-services-location:$google_services_version"
    implementation "com.google.android.gms:play-services-auth:$google_services_version"

    implementation('com.google.api-client:google-api-client:1.23.0') {
        exclude group: 'com.google.code.findbugs', module: 'jsr305'
    }
}

///////////////

I also upgraded graddle-wrapper.properties to:

#Wed Dec 20 15:08:34 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

This post is the top search result for the very similar error: "Program type already present: android.arch.lifecycle.ViewModelProvider$Factory"

My project uses Room and LiveData, but not firebase. The following changes removed the error:

FROM:

implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
implementation 'android.arch.lifecycle:extensions:1.0.0'
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0'

TO:

implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
implementation 'android.arch.lifecycle:extensions:1.1.1'
annotationProcessor 'android.arch.lifecycle:compiler:1.1.1'

--- UPDATED ANSWER ---

My previous answer was aimed at solving this error. However, I thought it would be worth presenting it again using best practises:

App level build.gradle file:

// Room components
implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"
androidTestImplementation "android.arch.persistence.room:testing:$rootProject.roomVersion"

// Lifecycle components
implementation "android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion"
annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion"

Project level build.gradle file:

ext {
   roomVersion = '1.1.1'
   archLifecycleVersion = '1.1.1'
}

Reference:
https://codelabs.developers.google.com/codelabs/android-room-with-a-view/#2

Firebase-UI 3.1.0 isn't compatible with Firebase / Google Services 11.8.0

You will need to upgrade or downgrade according to https://github.com/firebase/FirebaseUI-Android#compatibility-with-firebase--google-play-services-libraries

  • Firebase-UI 3.1.0 with Firebase / Google Services 11.4.2
  • Firebase / Google Services 11.8.0 with Firebase-UI 3.1.3

Hope this help ;)

I also had the error posted in the original question, namely:

Error:Program type already present: android.arch.lifecycle.LiveData

It wasn't clear which libraries were causing the problem. With a hint from @lienmt above I realized that it may be related Firebase.

In my case, I am using Firebase and was also using firebase-ui library 3.2.2:

implementation 'com.firebaseui:firebase-ui-database:3.2.2'

I had upgraded all my other Firebase libraries to 15.0.0 but realized my firebase-ui library was incompatible and confirmed it here:

https://github.com/firebase/FirebaseUI-Android#compatibility-with-firebase--google-play-services-libraries

Be sure to match your firebase-ui version to the exact Firebase versions that for which they are fixed for pairing.

Bumping my firebase-ui version to 3.3.1 was what resolved the error:

implementation 'com.firebaseui:firebase-ui-database:3.3.1'

For reference here are the versions I'm using now and my app is running with no errors:

implementation 'com.google.android.gms:play-services-wearable:15.0.0'
implementation 'com.google.android.gms:play-services-auth:15.0.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-database:15.0.0'
implementation 'com.google.firebase:firebase-core:15.0.0'
implementation 'com.google.firebase:firebase-auth:15.0.0'
implementation 'com.google.firebase:firebase-messaging:15.0.0'
implementation 'com.firebaseui:firebase-ui-database:3.3.1'

Please add following dependencies in your app build.gradel file

implementation "android.arch.core:runtime:1.1.1"
implementation "android.arch.core:common:1.1.1"

@Edric: since I couldn't replay with images in the thread I am answering your question here.

Changes that worked for me:

PS: I also upgraded distributionUrl in gradle-wrapper.properties to http://services.gradle.org/distributions/gradle-4.6-all.zip

Like Edric mention, this happens because some library still use the old version of android.arch.lifecycle:extensions library, that is android.arch.lifecycle:extensions:1.0.0.

One way to handle this is by forcing the app to use the same version of that library (and if we can, use the newest one).

There are two ways to do that:

  1. Explicitly defined the library version that we want to use in our Gradle, under dependencies section.

    implementation 'android.arch.lifecycle:extensions:1.1.1

or

  1. Force resolution of the library, also under dependencies section.

    android {
        configurations.all {
            resolutionStrategy.force 'android.arch.lifecycle:extensions:1.1.1'
        }
    }
    

In my case, bumping targetSdkVersion and compileSdkVersion to 28, as well as using version 28 of all support libraries fixed the issue.


I encountered this when I upgraded Glide. I got an error regarding a duplicate CoordinatorLayout. I solved that by using com.android.support:design:27.1.0, but then I got another error regarding LiveData$LifecycleBoundObserver.

After a few hours, I gave up and upgraded targetSdkVersion and compileSdkVersion to API 28, as well as using

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'

because YOLO. By dumb luck, it worked.

Just gotta upgrade. For me I had to upgrade the following in App build.gradle file:

implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.2.0'
implementation 'com.firebaseui:firebase-ui-database:3.2.2'

Then you will sync your files. When you run you will get a new issue of installation failed pop up boxes. Just cancel those and do the following:

1) Build -> Clean Project
2) Build -> Build Bundle(s) / APK(s) -> Build APK(s)
3) Run your project! Should work!

Follow this link if you want any other details on how I solved it but this should do the trick!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!