Android studio application crash when i add firestore [closed] - android

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I want use firebase in my app.
In my app I only use firebaseauth (without problems) but now i want use FirebaseFirestore (currently I don't have this in code yet) but when i add
implementation 'com.google.firebase:firebase-firestore:21.6.0'
in gradle my app start without errors and then crashes.
Where can i find the problem?
FirebaseUser user = mAuth.getCurrentUser();
DocumentReference df=fStore.collection("users").document(user.getUid());
Map<String,Object> userInfo= new HashMap<>();
userInfo.put("Email",mail);
userInfo.put("Name",name);
userInfo.put("Surname",surname);
userInfo.put("Phone",phone);
userInfo.put("Role","0");//0-user 1-admin 2- courier
df.set(userInfo);
build.gradle
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-firestore:21.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

Your Firebase library versions don't match - Firebase Auth is too old compared to Firestore. If you add any library, you have to also have to make sure that all the other versions of the libraries are compatible with it. It's easiest to simply use the latest versions of everything that you see in the release notes. Minimally, you should upgrade firebase-auth to 19.4.0.
implementation 'com.google.firebase:firebase-auth:19.4.0'
implementation 'com.google.firebase:firebase-firestore:21.6.0'

Related

Android: cannot resolve symbol FirebaseDatabase

I'm new to android and using firebase for an android app.
I have added the firebase realtime database by using the firebase assistant provided by android studio.
When I try proceeding with adding firebase code, android studio shows the error "cannot resolve..." with anything firebase related.
DatabaseReference myRef = database.getReference("message");
myRef.setValue("Hello, World!");
I have looked for a solution everywhere, re-added firebase multiple times and it still won't work. Of course, I have checked for the correct dependencies in the gradle scripts.
This is what it looks like currently:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-database:19.2.0'
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-firestore:21.3.1'
I would really appreciate some help. I might have missed something small due to being a beginner.

AutoComplete can't be found in new compatibility library and Gives Program Type Already Present With New Places Library

I was trying to add an AutoComplete feature while letting user select a place. I followed the official documents and implemented the feature. But if I just use the compatibility library ('com.google.android.libraries.places:places-compat:2.0.0') and don't use the new places library ('com.google.android.libraries.places:places:2.0.0') I cannot import anything useful related to AutoComplete.(only 4 classes from widget which are not useful for coding and I believe they cause the program type already present error when I include the new places library)
To start auto complete I use this code
val fields = Arrays.asList(Place.Field.ID,
Place.Field.NAME,
Place.Field.ADDRESS,
Place.Field.ADDRESS_COMPONENTS,
Place.Field.LAT_LNG,
Place.Field.OPENING_HOURS,
Place.Field.PHONE_NUMBER,
Place.Field.PRICE_LEVEL,
Place.Field.RATING,
Place.Field.TYPES,
Place.Field.PHOTO_METADATAS,
Place.Field.TYPES,
Place.Field.VIEWPORT,
Place.Field.USER_RATINGS_TOTAL)
val intent = Autocomplete.IntentBuilder(
AutocompleteActivityMode.FULLSCREEN, fields)
.build(this#AddPartnerActivity)
startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE)//Request code is just a number
}
Android doesn't suggest me any useful import while new places library is missing.When I use exclude in gradle Error: Program type already present: com.google.android.libraries.places.widget.AutocompleteActivityis not fixed. I can also paste my gradle file for your reference (it's a mess and I tried to write exclude into any import that can possibly create a problem). One important thing to note is code was working fine without adding the new places api if I don't use autocomplete.
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation ('com.google.android.gms:play-services-maps:16.0.0'){
exclude group: 'com.google.android.libraries.places.widget'
}
//Ion
implementation 'com.koushikdutta.ion:ion:2.+'
//Facebook Login
implementation 'com.facebook.android:facebook-login:4.41.0'
//Google Login
implementation 'com.google.android.gms:play-services-auth:16.0.1'
//Anko
implementation "org.jetbrains.anko:anko:$anko_version"
// Anko Layout
implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
implementation "org.jetbrains.anko:anko-commons:$anko_version"
implementation "org.jetbrains.anko:anko-design:$anko_version"
//Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'jp.wasabeef:picasso-transformations:2.2.1'
//PlaceholderView
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.mindorks.android:placeholderview:1.0.3'
kapt 'com.mindorks.android:placeholderview-compiler:1.0.3'
//Web Sockets
implementation 'com.koushikdutta.async:androidasync:2.+'
implementation 'com.squareup.okhttp3:okhttp:3.12.3'
//Gson
implementation 'com.google.code.gson:gson:2.8.5'
//Firebase Cloud Messaging
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-database:19.0.0'
implementation 'com.google.android.play:core:1.5.0'
//Kotlin Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1'
//Firebase Crashlytics
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
//Map Utility
implementation 'com.google.maps.android:android-maps-utils:0.5+'
//room
implementation 'androidx.room:room-runtime:2.0.0'
kapt 'androidx.room:room-compiler:2.0.0'
implementation 'com.google.android.gms:play-services-oss-licenses:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation ('com.schibstedspain.android:leku:6.2.1') {
exclude group: 'com.google.android.gms'
exclude group: 'androidx.appcompat'
exclude group: 'com.google.android.libraries.places.widget'
}
implementation ('com.google.android.libraries.places:places-compat:2.0.0'){
exclude group: 'com.google.android.libraries.places.widget'
}
implementation 'com.google.android.libraries.places:places:2.0.0')
apply plugin: 'com.google.gms.google-services'
My first mistake was that in compatibility library, I should use the Place prefix with AutoComplete to find the necessary imports.
val intent = PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN).build(this#AddPartnerActivity)
Second issue was that I wanted to get the property opening_hours(and data about photos) from Placeobject which was present in new places library, but not present in compatibility library. In compatibility library to retrieve this, one should send a query instead of creating a list of types he wants to retrieve directly from the place object like I did in the question.
Basically one should sent a request to this url using the id retrieved from autocomplete. Documentation for this can be found here place details
val url = "https://maps.googleapis.com/maps/api/place/details/json?placeid=$placeId&fields=opening_hours,photos,reviews&key=YOUR_API_KEY" //place id is the id of the place you got from autocomplete
My confusion came from the fact that you need to send a query in one library which I thnk is subject to billing while in the new api you can directly retrieve the opening hours.

error: cannot find symbol import com.firebase.ui.database.FirebaseRecyclerAdapter;

I have the right library and dependencies the build gradle(app) file. But I'm still etting this error.
According to some answers here, I have already tried all of them. I already checked if i have the right version, whether i have included the package correctly, whether the package name is same in google-service.json file, in manifest file, or in gradle file. I have already done all these.
// All google dependencies
implementation 'com.google.android.gms:play-services-maps:12.0.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.google.android.gms:play-services-places:12.0.1'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.google.firebase:firebase-database:12.0.1'
implementation 'com.google.firebase:firebase-auth:12.0.1'
implementation 'com.google.firebase:firebase-messaging:12.0.1'
implementation 'com.firebaseui:firebase-ui:3.3.0'
implementation 'com.firebase:firebase-client-android:2.5.2'
implementation 'com.google.firebase:firebase-core:12.0.1'
implementation 'com.google.android.gms:play-services-gcm:12.0.1'
implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.github.ar-android:DrawRouteMaps:1.0.0'
these are backdated on purpose.
as this answer(https://stackoverflow.com/a/39217164/11686135) suggests, i have already done that:
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
and this is the error its showing: Cannot resolve symbol 'database'
maybe somehow the dependencies not working...?
i am really novice at this. thanks in advance
Perhaps you are missing a dependency, please refer to the
GitHub project for FirebaseUI,
you might be missing just one more dependency such as any of these:
dependencies {
// FirebaseUI for Firebase Realtime Database
implementation 'com.firebaseui:firebase-ui-database:5.0.0'
// FirebaseUI for Cloud Firestore
implementation 'com.firebaseui:firebase-ui-firestore:5.0.0'
// FirebaseUI for Firebase Auth
implementation 'com.firebaseui:firebase-ui-auth:5.0.0'
// FirebaseUI for Cloud Storage
implementation 'com.firebaseui:firebase-ui-storage:5.0.0'
}
if someone is getting same issue then try searching for Firebase Dependencies latest version
and add it issue will be resolved
These are Latest dependencies add accordingly for use
To learn more
click here
dependencies {
// FirebaseUI for Firebase Realtime Database
implementation 'com.firebaseui:firebase-ui-database:6.3.0'
// FirebaseUI for Cloud Firestore
implementation 'com.firebaseui:firebase-ui-firestore:6.3.0'
// FirebaseUI for Firebase Auth
implementation 'com.firebaseui:firebase-ui-auth:6.3.0'
// FirebaseUI for Cloud Storage
implementation 'com.firebaseui:firebase-ui-storage:6.3.0'
}
Firebaserecycleroption.
Basically android studio will change their version.
but build.gradle old dependencies are working in new version. So guys try to all dependecies in gradle.
gradle build dependencies:
compile 'com.firebaseui:firebase-ui-database:2.0.0'
implementation 'com.firebaseui:firebase-ui-database:4.3.2'
implementation 'com.firebaseui:firebase-ui-firestore:4.3.1'
implementation 'com.firebaseui:firebase-ui-database:5.0.0'
implementation 'com.firebaseui:firebase-ui-database:6.3.0'
//( Below two dependencies are same apply both )
compile 'com.firebaseui:firebase-ui-database:0.4.0'
compile'com.firebaseui:firebase-ui-database:1.1.1'
implementation 'com.firebaseui:firebase-ui-database:8.0.1'
( must try it )

RxTextView and other widgets not found while using latest com.jakewharton.rxbinding3:rxbinding:3.0.0-alpha2 library

I wanna use RxJava binding APIs for Android UI widgets in my project.
Therefore following the guidance as per this site 'https://github.com/JakeWharton/RxBinding'
But I am unable to import any Android UI widgets in my Kotlin File.
Where as its working fine if I am consuming these widgets in Java File.
Hence, not been to find the actual of this issue.
For reference following are the gradle file and class files(both kotlin and java) using in same project
build.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.core:core-ktx:1.2.0-alpha01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'io.reactivex.rxjava2:rxjava:2.2.8'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
//RxBinding
implementation 'com.jakewharton.rxbinding3:rxbinding:3.0.0-alpha2'
}
BindingExample.java class
RxBindingExample.kt class
Have tried exploring this issue on S.O. but questions or solutions are available for previous version of lib 'com.jakewharton.rxbinding2:rxbinding'
Check this reference:
https://github.com/JakeWharton/RxBinding/blob/master/rxbinding/src/main/java/com/jakewharton/rxbinding3/widget/TextViewTextChangeEventObservable.kt
There are different ways to use depending on the language, note the #file:JvmName("RxTextView") at the start. If you're using java the class RxTextView is visible, in kotlin you should use the extension functions provided by the lib, textChangeEvents() is an example of it.
like that, this will aquire the observable e.g.:
val someTextView = TextView(context)
someTextView.textChangeEvents()
Edit:
Seems that the old class that I've referenced was deleted, here is another one:
https://github.com/JakeWharton/RxBinding/blob/master/rxbinding/src/main/java/com/jakewharton/rxbinding4/widget/TextViewAfterTextChangeEventObservable.kt

cannot resolve method 'arrayUnion' - firestore

I was looking in the following google documentation of firestore and especially on the part of updating an array. they mention:
Update elements in an array
If your document contains an array field, you can use arrayUnion() and arrayRemove() to add and remove elements. arrayUnion() adds elements to an array but only elements not already present. arrayRemove() removes all instances of each given element.
problem is, Android studio can't resolve the method arrayUnion.
relevant part of the code:
public void onClick(View view) {
if(isStringValid(newListName.getText().toString())){
currListName = newListName.getText().toString().trim();
itemList mList = new itemList(currListName , mAuth.getCurrentUser().getEmail());
Map<String , Object> listMap = new HashMap<>();
listMap.put(KEY_LIST_NAME , currListName);
listMap.put(KEY_OWNER , mAuth.getCurrentUser().getEmail());
listMap.put(KEY_HAS_ACCESS , Arrays.asList(mAuth.getCurrentUser().getEmail()));
userRef.update("hasAccess" , FieldValue.arrayUnion(currListName));
gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:28.0.0-rc02'
implementation 'com.android.support:design:28.0.0-rc01'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-firestore:17.0.1'
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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.android.gms:play-services-auth:16.0.0'
}
their code:
DocumentReference washingtonRef = db.collection("cities").document("DC");
washingtonRef.update("regions", FieldValue.arrayUnion("greater_virginia"));
I found two FieldValue classes in Firebase Firestore SDK (21.0.0):
com.google.firebase.firestore.model.value.FieldValue
com.google.firebase.firestore.FieldValue
The first has no arrayUnion method, and second has it. Check what class is imported in your code file.
According to the release notes, array operations are supported starting with client SDK version 17.0.5. Here's a link to the release notes.
An any case, update your client SDK to use the latest Firestore APIs.

Categories

Resources