Can't import "import com.google.firebase.firestore.MetadataChanges" - java

I have a question about the FirestoreRecyclerOptions :
The FirestoreRecyclerOptions cannot import
com.google.firebase.firestore.MetadataChanges
When I compile my program I have the following error
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/firestore/MetadataChanges
I think it's a version problem in the gradle. Do you know how to fix this?
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.firebaseui:firebase-ui-auth:4.3.0'
//Firestore
implementation 'com.google.firebase:firebase-firestore:18.0.1'
// FirebaseUI for Cloud Firestore
implementation 'com.firebaseui:firebase-ui-firestore:4.3.1'
implementation 'com.google.firebase:firebase-functions:16.1.3'
implementation 'com.firebaseui:firebase-ui-storage:4.3.1'
The function when i call the recycleroption
private FirestoreRecyclerOptions<chat> generateOptionsForAdapter(Query query){
return new FirestoreRecyclerOptions.Builder<chat>()
.setQuery(query,chat.class)
.setLifecycleOwner(this)
.build();
}

Related

Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-java-3.15.3

I tried to add the firestore dependency and after I did this I got a error saying the following:
Caused by: java.lang.RuntimeException: Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-java-3.15.3 (com.google.protobuf:protobuf-java:3.15.3) and protobuf-javalite-3.19.2 (com.google.protobuf:protobuf-javalite:3.19.2)
The following code are all the dependencies I use hope someone can find the problem.
dependencies {
implementation("androidx.compose.foundation:foundation:1.2.0-alpha07")
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.4.0"
// Hilt
implementation "com.google.dagger:hilt-android:2.40.5"
kapt "com.google.dagger:hilt-compiler:2.40.5"
// Room
implementation "androidx.room:room-runtime:2.4.1"
implementation "androidx.room:room-ktx:2.4.1"
kapt "androidx.room:room-compiler:2.4.1"
// Navigation
implementation "androidx.navigation:navigation-compose:2.4.0"
implementation "androidx.hilt:hilt-navigation-compose:1.0.0"
//animated navigation
implementation "androidx.navigation:navigation-compose:2.5.0-alpha04"
//implementation "com.google.accompanist:accompanist-navigation-animation:0.16.0"
//IGDB
implementation 'com.github.husnjak:IGDB-API-JVM:1.0.5'
testImplementation "androidx.arch.core:core-testing:2.1.0"
//coil
implementation("io.coil-kt:coil-compose:2.0.0-rc01")
//fuel
implementation 'com.github.kittinunf.fuel:fuel-android:2.3.1'
//system ui
implementation "com.google.accompanist:accompanist-systemuicontroller:0.17.0"
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:29.3.1')
// When using the BoM, you don't specify versions in Firebase library dependencies
// Declare the dependency for the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-analytics-ktx'
// Declare the dependencies for any other desired Firebase products
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-firestore'
}

Unable to add dependency: Failed to resolve: androidx.lifecycle:lifecycle-extensions:2.2.0-rc2

I am trying to add few dependencies to my Android project but I'm still getting some weird errors.
I am trying to add recommended dependencies which I've found on CodeLabs but it steel does not allow me to sync my gradle files successfully.
The error that is keep showing up is the following: ERROR: Failed to resolve: androidx.lifecycle:lifecycle-extensions:2.2.0-rc2
Code: inside gradle module
// Room components
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
annotationProcessor "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"
// Lifecycle components
implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.archLifecycleVersion"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$rootProject.archLifecycleVersion"
// UI
implementation "com.google.android.material:material:$rootProject.materialVersion"
// Testing
androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
Text inside gradle project:
ext {
roomVersion = '2.2.1'
archLifecycleVersion = '2.2.0-rc2'
coreTestingVersion = '2.1.0'
materialVersion = '1.0.0'
}
This is also one error that I am getting sometimes, it appears randomly...
ERROR: Manifest merger failed : Attribute application#appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.1.0] AndroidManifest.xml:24:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:11:5-28:19 to override.
The error log literally says there is no androidx.lifecycle:lifecycle-extensions version 2.2.0-rc2.
Change archLifecycleVersion = '2.2.0-rc2' to archLifecycleVersion = '2.2.0-rc02' to fix that error.
The APIs in lifecycle-extensions have been deprecated. Instead, add dependencies for the specific Lifecycle artifacts you need.
dependencies {
def lifecycle_version = "2.2.0"
def arch_version = "2.1.0"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
// Lifecycles only (without ViewModel or LiveData)
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
// Saved state module for ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
// Annotation processor
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
// alternately - if using Java8, use the following instead of lifecycle-compiler
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
// optional - helpers for implementing LifecycleOwner in a Service
implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version"
// optional - ProcessLifecycleOwner provides a lifecycle for the whole application process
implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"
// optional - ReactiveStreams support for LiveData
implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version"
// optional - Test helpers for LiveData
testImplementation "androidx.arch.core:core-testing:$arch_version"
}
From this source

android build error: can't find symbol class IntDef

Using Android Studio to build the android version of a react native app. I just received
'error: cannot find symbol class IntDef'
It's used in the following code:
#IntDef(flag = true, value = { Information.BATTERY, Information.RSSI, Information.API_VERSION, Information.LED,
Information.APPLICATION_VERSION })
the bottom of my dependencies block looks like this:
implementation 'androidx.multidex:multidex:2.0.0'
implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
Do I need to make an import at the top of this file..or is do I need to add to the build.gradle such as implementation 'androidx.appcompat:appcompat:1.0.0'
inside the dependencies block?
I had the same issues except it was with ArrayMap, this was fixed by adding
compile "com.android.support:support-core-utils:24.2.0"
in the dependencies
You probably will have to include the following in your build.gradle file:
dependencies {
implementation 'com.android.support:support-annotations:28.0.0'
}
And the import statement in your class would be such :
import android.support.annotation.IntDef;

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp$IdTokenListener;

I'm trying to use Firebase for a simple CRUD android app, but while instantiation of a Firebase database reference, I encounter the following exception at runtime:
java.lang.RuntimeException: Uncaught exception in Firebase Database runloop (3.0.0). Please report to firebase-database-client#google.com
at com.google.firebase.database.android.AndroidPlatform$1$1.run(com.google.firebase:firebase-database##16.1.0:98)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
....
....
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp$IdTokenListener;
....
....
at com.satwick.employeecrud.MainActivity.onCreate(MainActivity.java:76)
I went through StackOverflow, and although there have been many cases of NoClassDefFoundError in Firebase, none of them were about IdTokenListener. What I mainly realized is this might've been an error of missing some steps, while setting up the Firebase database. So I rechecked all steps:
Ensured my app is registered with the Firebase project, with correct signing SHA1.
google-services.json is included in my app directory.
firebase is correctly loaded in the application's and project's gradle files. (I can complete phone number authentication for now, so I'm pretty sure.)
In the onCreate() method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize Firebase Auth
mFirebaseAuth = FirebaseAuth.getInstance();
mFirebaseUser = mFirebaseAuth.getCurrentUser();
if (mFirebaseUser == null) {
List<AuthUI.IdpConfig> providers = Arrays.asList(new AuthUI.IdpConfig.PhoneBuilder().build());
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.build(),
RC_SIGN_IN);
} else {
mUsername = mFirebaseUser.getDisplayName();
}
// MainActivity.java:76 The following line causes the exception.
mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
}
Is this a bug with Firebase? Or am I doing something wrong?
Please help.
Also, I don't know if this is related or not, but I have two applications registered with the same Firebase project, with the same signing key (Android Studio's default SHA1.)
EDIT 1 -
Adding dependencies {} of build.gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0-alpha07'
// Google
implementation 'com.google.android.gms:play-services-auth:16.0.1'
// Firebase
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation platform('com.google.firebase:firebase-bom:17.0.0')
implementation 'com.google.firebase:firebase-database'
implementation 'com.google.firebase:firebase-storage'
implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
// Firebase UI
implementation 'com.firebaseui:firebase-ui-database:3.3.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
I was using some unwanted libraries in build.gradle, so cleared off the clutter to the following imports for Firebase:
// Firebase
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-auth:17.0.0'
// Firebase UI
implementation 'com.firebaseui:firebase-ui-auth:5.0.0'
implementation 'com.firebaseui:firebase-ui-database:5.0.0'
Consequently, I tried updating the version of firebase-ui from 4.3.1 -> 5.0.0, and it worked.
I tried downgrading my version from
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
to
implementation 'com.firebaseui:firebase-ui-auth:4.3.0'
and
implementation 'com.google.firebase:firebase-database:19.2.0'
to
implementation 'com.google.firebase:firebase-database:16.0.4'
and it worked

GlideApp cannot be found

error: cannot find symbol variable GlideApp
This is the error I have been getting.
I'm using Android studio 3.3.1 and imported these modules for glide.
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
GlideApp.with(this /* context */)
.load(storageReference)
.into(MainImage);
If GlideAPP can't be generated
annotationProcessor com.github.bumptech.glide:compiler:4.9.0
Must be with ‘AppGlideModule Implementation class’ In the same module
To use generated API in Glide you need to create a class and extend AppGlideModule and use #GlideModule annotation, for example:
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
#GlideModule
public final class MyAppGlideModule extends AppGlideModule {
}
After this rebuild and you should be able to use GlideApp for more information visit:
http://bumptech.github.io/glide/doc/generatedapi.html
def glide_version = "4.12.0"
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"
Then Sync it will work.
Working Screenshot
Optional: You can also do this. Build -> Make Module
If you use Kotlin, try to use kapt instead of annotationProcessor.
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"

Categories

Resources