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

前端 未结 10 931
迷失自我
迷失自我 2020-12-06 04:32

When I press the run button in Android Studio, my app compiles but shows this error (redacted):

Error:Program type a         


        
相关标签:
10条回答
  • 2020-12-06 05:00

    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 ;)

    0 讨论(0)
  • 2020-12-06 05:01

    @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

    0 讨论(0)
  • 2020-12-06 05:01

    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'
          }
      }
      
    0 讨论(0)
  • 2020-12-06 05:02

    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.

    0 讨论(0)
  • 2020-12-06 05:05

    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

    0 讨论(0)
  • 2020-12-06 05:05

    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!

    0 讨论(0)
提交回复
热议问题