How to get Firebase Token in android activity? - android

I am using setToken(FirebaseInstanceId.getInstance().getToken()) code to get the token but I am getting the following error
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/zzv;
build.gradle
dependencies {
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'android.arch.lifecycle:extensions:1.1.0'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
annotationProcessor "android.arch.lifecycle:compiler:1.1.0"
//noinspection GradleCompatible
implementation 'com.android.support:recyclerview-v7:28.0.0-rc02'
implementation 'pub.devrel:easypermissions:0.4.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0-rc02'
implementation 'com.google.firebase:firebase-messaging: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'
implementation 'net.bohush.geometricprogressview:geometricprogressview:1.1.1'
implementation project(path: ':andoird-sdk')
implementation project(path: ':opentok-android-sdk-2.16.3')
implementation 'com.android.support:multidex:1.0.3'
}
apply plugin: 'com.google.gms.google-services'
The above code is my build.gradle. Help me to fix the issue.

you need to use FirebaseMessagingService to get token .. you will get token into its own method
public class MyFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onNewToken(final String token) {
/// you will get token here you
enter code here
}
}

First of all fix version of all firebase library to latest version.
you cant mix versions <= 12 and versions >= 15 of Firebase libraries as mentioned here
then check you have properly enable Multidex on your project. Enable multidex for apps with over 64K methods
then use build -> clean to cleanup your project and dependencies.
and for using token use the way of #sonali:

Related

Kotlin compiler throwing annotation errors after changes made to the build.gradle file

I have made the following changes to my build.gradle(app) file.
apply plugin: 'kotlin-kapt'
and
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha05'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha07'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-alpha01'
kapt 'androidx.lifecycle:lifecycle-compiler:2.0.0-rc01'
implementation 'androidx.room:room-runtime:2.1.0-rc01'
kapt 'androidx.room:room-compiler:2.0.0-rc01'
implementation 'androidx.paging:paging-runtime:2.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'io.sentry:sentry-android:1.7.16'
implementation 'org.slf4j:slf4j-nop:1.7.25'
}
And now the Kotlin compiler is throwing the following error about my EntryDAO.kt and EntryDatabase.kt files:
The error message is quite clear.
The room’s Delete, Update methods signature has changed. It needs to return void or int.
Edit: I checked again, your gradle file mixed androidx library and pre-AndroidX versions of Lifecycle.
Please follow the link to use the correct library combination: https://developer.android.com/jetpack/androidx/releases/lifecycle

Error: Program type already present: com.google.android.gms.internal.measurement.zzdz after adding analytics

After I added google analytics I get this error, can't find a solution yet...
here is my gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:support-v4:28.0.0-rc02'
implementation 'com.android.support:design:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.skyfishjy.ripplebackground:library:1.0.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.budiyev.android:circular-progress-bar:1.2.0'
implementation 'com.github.channguyen:adv:1.0.0'
implementation 'com.github.jetradarmobile:android-snowfall:1.2.0'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.github.Binary-Finery:Bungee:master-SNAPSHOT'
implementation 'jp.wasabeef:recyclerview-animators:2.3.0'
implementation 'com.google.firebase:firebase-ads:17.1.0'
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.android.support:support-dynamic-animation:28.0.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.5' //added this and got this error!
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'
build.gradle (Module:app) this code:
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.6'
}
apply plugin: 'com.google.gms.google-services'`
and
build.gradle (Project:project) this code:
dependencies {
classpath 'com.google.gms:google-services:4.0.1'
}
this work for me.
I think it's because you have used a libraries for Firebase with Google Analytics Services SDK for Android.
It says from the documentation, Add Analytics to Your Android App that Firebase SDK is the recommended method to track Android Apps. There's a service from Firebase library you can use.
Analytics com.google.firebase:firebase-analytics:16.0.5
You can view here the other latest versions of Firebase SDK for Android.
If you want to continue to use Google Analytics Services SDK for Android, you can follow the guide from the documentation.

How to use implementation 'com.google.firebase:firebase-auth:16.0.3:15.0.0' not work

I use the latest version of Android Studio 3.2 & Plugin. When I try to connect firebase it show me to add dependencies -implementation 'com.google.firebase:firebase-auth:16.0.3:15.0.0' for Firebase authentication | implementation 'com.google.firebase:firebase-database:16.0.1:15.0.0' for Realtime Database | implementation 'com.google.firebase:firebase-storage:16.0.1:15.0.0' for Cloud Storage
When using these dependencies it connect Firebase properly but Sync Failed. How to Use these dependencies?
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design: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:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-auth:16.0.3:15.0.0'
implementation 'com.google.firebase:firebase-database:16.0.1:15.0.0'
implementation 'com.google.firebase:firebase-storage:16.0.1:15.0.0'
}
apply plugin: 'com.google.gms.google-services'
I had faced the same issue before. If there is the update available then update your android it will fix it. from my experience when I use the assistant to add the dependencies then it comes like this
implementation 'com.google.firebase:firebase-database:16.0.1:15.0.0'
but the it is not correct update it with this
implementation 'com.google.firebase:firebase-database:16.0.1'
or
implementation 'com.google.firebase:firebase-database:15.0.0'
or this
maybe this will help you
here is official documentation for help
Update you firebase dependencies like this:
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
Basically, remove the last ":15.0.0" part. You probably copied these from the firebase website and made a mistake while pasting

Cannot resolve symbol 'OnSuccessListener' in Android Studio

I'm getting this strange behavior that I'm not able to import OnSuccessListener to my code after git cloning and building in a different machine (this resolved fine in my previous machine). However the project builds fine and runs on the emulator. But I'm not able to write firebase related codes further as the listener isn't resolving.
I tried cleaning the project, rebuilding, invalidating the cache but still no luck.
Gradle Dependencies,
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:27.1.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 'com.google.firebase:firebase-firestore:17.0.4'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
implementation 'com.android.support:design:27.1.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.github.drawers:SpinnerDatePicker:1.0.6'
implementation 'com.github.yalantis:ucrop:2.2.2'
}
Please try adding this into your app-gradle file.
implementation 'com.google.android.gms:play-services-tasks:16.0.1'
What you do is make all the firebase and gms version of the same number like for example:
implementation 'com.google.firebase:firebase-auth:102.0'
implementation 'com.google.android.gms:play-services-auth:10.2.0'

Got Error when adding googlemaps

Here is my dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:design:26.1.0'
implementation 'com.koushikdutta.ion:ion:2.2.1'
implementation 'com.firebase:firebase-client-android:2.5.2'
implementation 'com.google.firebase:firebase-core:11.6.2'
implementation 'com.google.firebase:firebase-messaging:11.6.2'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
}
apply plugin: 'com.google.gms.google-services'
when I added the last implementation which is com.google.android.gms:play-services-maps:15.0.1, I Got this error:
All firebase libraries must be either above or below 14.0.0
what's the problem?
You have two different Firebase. First, you're using the old version of firebase with:
implementation 'com.firebase:firebase-client-android:2.5.2'
Second, you're using the more recent Firebase version:
implementation 'com.google.firebase:firebase-core:11.6.2'
implementation 'com.google.firebase:firebase-messaging:11.6.2'
So, you need to migrate your old Firebase. You can do that by changing the old firebase dependency with:
implementation "com.google.firebase:firebase-database:15.0.0"
You must see the full step to migrate from your old Firebase on
Upgrade your Android app from Firebase.com
Also, you need to use the same version of Firebase and Google Play Service. In the end, your dependencies will be like this:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:design:26.1.0'
implementation 'com.koushikdutta.ion:ion:2.2.1'
implementation "com.google.firebase:firebase-database:15.0.0"
implementation 'com.google.firebase:firebase-core:15.0.0'
implementation 'com.google.firebase:firebase-messaging:15.0.0'
implementation 'com.google.android.gms:play-services-maps:15.0.0'
}
apply plugin: 'com.google.gms.google-services'

Categories

Resources