When I press the play button in Android Studio, my app compiles but is shows this error (redacted):
Error:Program type already present: android.arch.lifecycle.LiveData
I've tried deleting the .gradle
folder, then going to Build > Clean Project
and Build > Rebuilt Project
. However, it doesn't work. I've also tried deleting the source code, then cloning again from git
and importing the folder to Android Studio. However, it still produces that error.
Here's my app's app/build.gradle
:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.edricchan.studybuddy"
minSdkVersion 24
targetSdkVersion 27
versionCode 8
versionName "1.0.0-rc.503"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resConfigs "en"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:support-annotations:27.1.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'
testImplementation 'junit:junit:4.12'
// Firebase stuff
implementation 'com.google.firebase:firebase-storage:11.8.0'
implementation 'com.google.firebase:firebase-firestore:11.8.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.google.android.gms:play-services-auth:11.8.0'
implementation 'com.firebaseui:firebase-ui-auth:3.1.0'
implementation 'com.firebaseui:firebase-ui-firestore:3.1.0'
implementation 'com.firebaseui:firebase-ui-storage:3.1.0'
// Provide a way to update the app
implementation 'com.github.javiersantos:AppUpdater:2.6.4'
// Chrome Custom Tabs
implementation 'com.android.support:customtabs:27.1.0'
// The app's intro screen
implementation 'com.heinrichreimersoftware:material-intro:1.6.2'
// Use for new Material Text field boxes recently introduced
implementation 'com.github.HITGIF:TextFieldBoxes:1.3.7'
// Report an issue to Github without having to open a new tab and so on...
implementation 'com.heinrichreimersoftware:android-issue-reporter:1.3.1'
}
apply plugin: 'com.google.gms.google-services'
@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
I also had the error posted in the original question, namely:
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:
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:
For reference here are the versions I'm using now and my app is running with no errors:
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:
TO:
--- 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:
Project level build.gradle file:
Reference:
https://codelabs.developers.google.com/codelabs/android-room-with-a-view/#2
Please add following dependencies in your app build.gradel file
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:
////////////////// app gradle libraries:
///////////////
I also upgraded graddle-wrapper.properties to:
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
Hope this help ;)