I have been working on a project where I am trying to build a messaging application in Android Studio using Google Firebase. I previously had to restart the project due to an error after reaching this stage of the tutorial I have been following which requires you to add an implementation of the 'com.firebaseui:firebase-ui-database:4.1.0' (Or whatever the most recent version is) in my project gradle file and update the existing dependencies I am using accordingly.
I am still relatively new to app dev and as such don't want to mess up this project and start from scratch again by screwing up my gradle file. So could somebody show me what my build.gradle file should look like with the new dependency added and the existing dependencies correctly updated before syncing?
Info on adding the dependency can be found under this link, mainly under the 'Installation' and 'Dependencies' headings. https://github.com/firebase/FirebaseUI-Android
My current gradle file looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.conormcadorey.chatbox"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
implementation 'com.android.support:design:28.0.0-beta01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.android.support:support-v4:28.0.0-beta01'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-storage:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//creates a rounded user profile image
implementation 'de.hdodenhof:circleimageview:2.2.0'
//ArthurHub - allows user to crop their profile image
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.+'
//Picasso - image uploader
implementation 'com.squareup.picasso:picasso:2.71828'
}
apply plugin: 'com.google.gms.google-services'
ps - I appreciate that this may be a simple or obvious question, however when I attempted this myself I ended up having to rebuild the project from scratch so any help would be greatly appreciated.
Using Android Studio v3.1.3
According to the docs:
As of version 4.1.0, FirebaseUI has the following dependency versions:
Library Version
firebase-auth 16.0.1
play-services-auth 15.0.1
firebase-database 16.0.1
firebase-firestore 17.0.1
firebase-storage 16.0.1
Therfore change the following libraries:
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-storage:11.8.0'
into this:
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
Also add the firebase-core:
implementation 'com.google.firebase:firebase-core:16.0.1'
Your app gradle file now has to explicitly list com.google.firebase:firebase-core as a dependency for Firebase services to work as expected.
Related
I want to add google admob to one of my android app.
But it shows dependency conflict error while adding google services ads and firebase ads.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "package name"
minSdkVersion 21
targetSdkVersion 28
versionCode 2
versionName "2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation'com.android.support.test.espresso:espressocore:3.0.2'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation "org.jetbrains.anko:anko-commons:$anko_version"
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.facebook.shimmer:shimmer:0.4.0'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.skyfishjy.ripplebackground:library:1.0.1'
implementation 'com.sasank.roundedhorizontalprogress:roundedhorizontalprogress:1.0.1'
implementation 'com.google.firebase:firebase-auth:16.2.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.tomer:fadingtextview:2.5'
implementation 'com.google.firebase:firebase-ads:18.0.0'
implementation 'com.google.android.gms:play-services-ads:18.0.0'
}
apply plugin: 'com.google.gms.google-services'
any help will be highly appericated
You don't need to use both firebase-ads and play-services-ads. You should use only one of them. If you're using firebase-ads follow Firebase ads guide or follow Google Admob guide if you're planning to use Standard alone Google Admob SDK
You are using:
implementation 'com.google.firebase:firebase-ads:18.0.0'
implementation 'com.google.android.gms:play-services-ads:18.0.0'
You can check the official release notes:
Warning: This release is a MAJOR version update and breaking change.
The latest update to Google Play services and Firebase includes the following changes:
Migration from Android Support Libraries to Jetpack (AndroidX) Libraries. Libraries will not work unless you make the following changes in your app:
Upgrade com.android.tools.build:gradle to v3.2.1 or later.
Upgrade compileSdkVersion to 28 or later.
Update your app to use Jetpack (AndroidX); follow the instructions in Migrating to AndroidX.
Also the 'firebase-ads' dependency just brings in the existing 'play-services-ads' library. The Firebase SDK is part of Google Play services.
Check your project gradle if this is added -
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0'
You don't have to add admob when you have com.google.android.gms:play-services-ads:18.0.0, it include admob.
You are trying to ad admob twice, hence the error.
You can also remove
implementation 'com.google.firebase:firebase-ads:18.0.0'
Because it's also part of Google Play Services.
Error : Sync failed. Unresolved Android dependencies. Failed to resolve: com.android.support:appcompat-v7:28.1.1
Config:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.ercess.ercess_app1"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:appcompat-v7:28.1.1'
implementation 'com.squareup.picasso:picasso:2.71828'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
How to resolve this?
Replace
implementation 'com.android.support:appcompat-v7:28.1.1
with
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
Currently, the most recent available release for appCompat is 28.0.0-rc01, you are trying to pull an unavailable version of appcompat library.
Root cause: The version 28.1.1 is not exist.
Solution: Use the latest stable version
implementation 'com.android.support:appcompat-v7:27.1.1'
or use latest unstable version
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
Many answers already on this one but I feel like noone explaines how to keep it up to date, just how to fix this specific version. So here it is
The com.android.support:appcompat version must match the compileSdkVersion
It is preferable to use stable versions if you release to production
Look on the android website to find the lastest stable version that correspond to your compile version (even is this link gets broken, the info will be available somewhere on the official website)
Example, as of today (end of january 2019), the lastest stable support library version is 28.0.0 (according to android website), so the correct implementation is
implementation 'com.android.support:appcompat-v7:28.0.0'
you'd have to use api "com.android.support:appcompat-v7:27.1.1" -
or the later (future) api "androidx.appcompat:appcompat:1.0.2"
from androidx.
using "release candidates" and "alpha versions" is discouraged, because these are not well tested.
just see the official documentation ...it recommends 27.1.1.
I solved this by trial and error and using some of the answers above.
I changed the appcompat to a lower version "com.android.support:appcompat-v7:27.1.0"
along with changing
compileSdkVersion 27
and
targetSdkVersion 27
I'm still getting warnings but Picasso should now run.
You need also add: implementation 'com.android.support:support-v4:28.0.0' in your gradle file like this:
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
and this is a full implementation:
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
Please add these below dependencies to solve the issue, try it:
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:support-v13:27.1.1'
implementation 'com.android.support:design:27.1.1'
also change the version of AppCompat as:
implementation 'com.android.support:appcompat-v7:27.1.1'
AppCompat Sometimes doesn't work alone. Adding these might solve your issue.
replace
implementation 'com.android.support:appcompat-v7:28.1.1'
with
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
I am trying to understand ViewModel and LiveData concepts in android. I am making a practice project but when i added implementation 'androidx.lifecycle:lifecycle-extensions-ktx:2.0.0-alpha1' line in my app level gradle file it shows me
Failed to resolve:
androidx.lifecycle:lifecycle-extensions-ktx:2.0.0-alpha1.
I have searched on google for solution and i found this answer, it works when i compile only viewmodel library but if i compile extensions library using same method as implementation group: 'androidx.lifecycle', name:'lifecycle-extensions-ktx', version: '2.0.0-alpha1', it shows the same error as above.
I have also tried to find it on Maven repositories site here but i didn't have any information for how to compile it.
UPDATE
App Level Build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "***************"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation group: 'androidx.lifecycle', name:'lifecycle-extensions-ktx', version: '2.0.0-alpha1'
implementation group: 'androidx.lifecycle', name:'lifecycle-viewmodel-ktx', version: '2.0.0-alpha1'
}
UPDATE
As per #Dr.jacky's comment and Android Developers Documentation,
The APIs in lifecycle-extensions have been deprecated. Instead, add dependencies for the specific Lifecycle artifacts you need.
More Info at https://developer.android.com/jetpack/androidx/releases/lifecycle
I have found the answer. As Thunder Knight said here it seems to be that the repository was emptied somehow. Hence, you can not download it from the repository.. I agree with this and so i was looking for answer on mvnrepository.com and i found it here. I have to add
implementation group: 'androidx.lifecycle', name: 'lifecycle-extensions', version: '2.0.0-alpha1'
line for adding lifecycle-extensions and also i was adding -ktx in name of library but it was the mistake. In documentation they have not commented to add -ktx in line of lifecycle-extensions.
Credits:- #Thunder Knight
The current version is 2.2.0
use -ktx for kotlin implementation
and kapt for annotationProcesssor
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.2.0'
Check the developer site for more information
https://developer.android.com/topic/libraries/architecture/adding-components
Just dont use -ktx in lifecycle-extensions. There is no separate '-ktx' version of the dependency unlike in viewmodel
Add these line
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
and comment these lines
// testImplementation 'junit:junit:4.13.2'
//androidTestImplementation 'androidx.test.ext:junit:1.1.2'
//androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
in my case i was trying to using room with LiveData. and all i did was remove the suspend key word from the query method.
Reference: post in forums.bignerdranch.com
Error:
Failed to resolve: androidx.lifecycle:lifecycle-extensions:2.3.1
Solution:
The APIs in lifecycle-extensions have been deprecated. Instead, add dependencies for the specific Lifecycle artifacts you need.
More details: developer.android.com
So I'm following the official documentation to add the Material Components library to my project https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md
But it throws me the following error
"Failed to resolve: com.google.android.material:material:1.0.0-alpha1"
I've tried installing the repository and sync project that Android Studio suggest to no avail.
My project config
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com"
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and the app config
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "mlluell.eftremp"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-auth:15.1.0'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.google.firebase:firebase-database:15.0.1'
implementation 'com.google.firebase:firebase-storage:15.0.2'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.google.android.material:material:1.0.0-alpha1'
//imatges recyclerview
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
// FirebaseUI for Firebase Realtime Database
implementation 'com.firebaseui:firebase-ui-database:3.3.0'
// FirebaseUI for Firebase Auth
implementation 'com.firebaseui:firebase-ui-auth:3.3.0'
// FirebaseUI for Cloud Storage
implementation 'com.firebaseui:firebase-ui-storage:3.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
Instead of:
implementation 'com.google.android.material:material:1.1.0'
Use:
implementation group: 'com.google.android.material', name: 'material', version: '1.1.0-alpha05'
And it works.
Thought I'd share what fixed this for me now that I|O has started.
I had about the same initial setup as you. To get it working I had to change the following:
compileSdkVersion to 'android-P'
Support Libraries to '28.0.0-alpha1'
include api 'com.android.support:design:28.0.0-alpha1' in the dependencies block.
SDK Platform update - Android P Preview (latest)
targetSdkVersion 'P'
I then did the ritualistic 'Invalidate Caches / Restart' and rebuilt the project for good measure.
FOR ANDROIDX USERS:
You can implement as follows:
AndroidX:
implementation 'com.google.android.material:material:1.0.0'
Old build artifact users can use the following implementation:
implementation 'com.android.support:design:[Enter Design library version here]'
Use that version without square brackets.
You can find design library version via this link : https://mvnrepository.com/artifact/com.android.support/design/28.0.0
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
androidTestImplementation 'androidx.test:runner:1.2.0'`
Well that happened to me an hour ago...
I always suggest check the most basic issues for example:
Go to >> Gradle module.app:
implementation 'com.google.android.material:material:1.2.1'
When you have a syntax's error; Failed to resolve: com.google.android.material:material:x.x.x appears.
Have a great day!
Make sure your gradle.properties enabled AndroidX using the following Line:
android.useAndroidX = true
If not added then add this line and sync project again
Visit For More Details
For androidx users:
My problem got solved by just updating all the dependencies with latest version. It got solved in just 2 minutes. My previous version was 1.0.2 and showed same error. I just clicked on 'Show in Project Structure dialog' which appeared below the error. From there you will get options to update dependencies to latest version. For users other than androidx might be the same soution works.
When I press the run button in Android Studio, my app compiles but shows this error (redacted):
Error:Program type already present: android.arch.lifecycle.LiveData
(Full log)
I've tried deleting the .gradle folder, then going to Build > Clean Project and Build > Rebuild 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'
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:
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
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!