Hi Guys, Today i'll be discussing how to use Firebase which is present as a Assistant in Android Studio 2.2.1 Preview.
As we know Firebase is a Cloud Services Provider which was acquired by Google back in 2014 in order to help developer build better real-time apps.
Now Firebase will be available as Assistant in Android Studio upcoming version which will help us easliy integrate following :
1. Analytics
2. Cloud Messaging
3. Authenication
4. Real time Database
5. Storage
6. Crash Reporting etc..
Now using Assistant present in Android Studio to use/integrate one the above services is quite easy and fast.
Here i'll be going through the steps to integrate Crash Reporting via Firebase in one of my demo app.
By Crash Reporting you can track all the crashes that occurs in your app and rectify once to get the report via Firebase.
So here are the steps :
1. Go to Tools and select Firebase.
2. You will see the Assistant opened in the right side in a tab named Assistant.
3. Now Scroll down and click on Crash Reporting
4. Click on Setup Firebase Crash reporting
5. Now This will ask to to connect to Firebase.
6. Once you click on Connect it will take you to Browser and ask you to login via Google Account and will ask for permission.
7. After that Successful login you will be re-directed to Firebase Console and you can come back to Android Studio where it shows connected.
Note : This will automatically create your project inside google web console. Where make sure your Firebase Api is Enable for the project in case if you face
crash reporting problems.
8. Now you need to create a new Firebase project or select the existing Firebase Google project in which we wish to integrate Firebase.
Here you can create a new Firebase project.
After you select/create Firebase project and connect then it shows progress in Assistant like this :
Now once you are connected Assistance show you as connected as well.
After this we are all done setting up Firebase project and connection. Now Lets come to Coding part which is also a small part to do.
9. Now you need to add following Classpath into your buildscript dependencies
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.0.0'
}
}
10. After that you need to add following dependencies in your app level build.gradle
FirebaseCrash.logcat(Log.ERROR, TAG, "NPE caught");
FirebaseCrash.report(ex);
This Lines will send crash reports to cloud. And you can login to console and check the crash reports easliy there.
Note : Every crash is visible on console only after 20-25 minutes after it is reported.
In one of my demos i've created arithmetic exception to check the Firebase something like this :
try { int i = 10 / 0; }catch (Exception e){ FirebaseCrash.logcat(Log.ERROR, "Crash", "NPE caught"); FirebaseCrash.report(e); }
As we know Firebase is a Cloud Services Provider which was acquired by Google back in 2014 in order to help developer build better real-time apps.
Now Firebase will be available as Assistant in Android Studio upcoming version which will help us easliy integrate following :
1. Analytics
2. Cloud Messaging
3. Authenication
4. Real time Database
5. Storage
6. Crash Reporting etc..
Now using Assistant present in Android Studio to use/integrate one the above services is quite easy and fast.
Here i'll be going through the steps to integrate Crash Reporting via Firebase in one of my demo app.
By Crash Reporting you can track all the crashes that occurs in your app and rectify once to get the report via Firebase.
So here are the steps :
1. Go to Tools and select Firebase.
2. You will see the Assistant opened in the right side in a tab named Assistant.
3. Now Scroll down and click on Crash Reporting
4. Click on Setup Firebase Crash reporting
5. Now This will ask to to connect to Firebase.
6. Once you click on Connect it will take you to Browser and ask you to login via Google Account and will ask for permission.
7. After that Successful login you will be re-directed to Firebase Console and you can come back to Android Studio where it shows connected.
Note : This will automatically create your project inside google web console. Where make sure your Firebase Api is Enable for the project in case if you face
crash reporting problems.
8. Now you need to create a new Firebase project or select the existing Firebase Google project in which we wish to integrate Firebase.
Here you can create a new Firebase project.
After you select/create Firebase project and connect then it shows progress in Assistant like this :
Now once you are connected Assistance show you as connected as well.
After this we are all done setting up Firebase project and connection. Now Lets come to Coding part which is also a small part to do.
9. Now you need to add following Classpath into your buildscript dependencies
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.0.0'
}
}
10. After that you need to add following dependencies in your app level build.gradle
android { // ... } dependencies { // .. compile 'com.google.firebase:firebase-ads:9.2.0' } // ADD THIS AT THE BOTTOM apply plugin: 'com.google.gms.google-services'Note : Make sure you are using the latest version of Firebase and Google play services here 11. Add following dependencies to app level build.gradle as well
compile 'com.google.android.gms:play-services:9.2.0'12. Now all is done. You can following code lines to track crashes
FirebaseCrash.logcat(Log.ERROR, TAG, "NPE caught");
FirebaseCrash.report(ex);
This Lines will send crash reports to cloud. And you can login to console and check the crash reports easliy there.
Note : Every crash is visible on console only after 20-25 minutes after it is reported.
In one of my demos i've created arithmetic exception to check the Firebase something like this :
try { int i = 10 / 0; }catch (Exception e){ FirebaseCrash.logcat(Log.ERROR, "Crash", "NPE caught"); FirebaseCrash.report(e); }
Which reported the Crash to console which was available to check after 20-25 minutes.
Once Crash occurs Firebase service starts and sends the crash details up to cloud.
You can find the below log in you logcat when Firebase service runs successfully.
Logcat Details which ensures Firebase Sent the Report successfully :
D/FirebaseCrashApiImpl: throwable java.lang.ArithmeticException: divide by zero
I/FirebaseCrashReceiverServiceImpl: FirebaseCrashReceiverServiceImpl created by
ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader
[DexPathList[[zip file "/data/user/0/com.google.android.gms/app_chimera/m/00000005/
DynamiteModulesC_GmsCore_prodmnc_xxhdpi_release.apk"],nativeLibraryDirectories=
[/data/user/0/com.google.android.gms/app_chimera/m/00000005/n/armeabi-v7a,
/data/user/0/com.google.android.gms/app_chimera/m/00000005/n/armeabi,
/vendor/lib, /system/lib]]] com.youpackage:background_crash D/FirebaseCrashReceiverServiceImpl: onCreate
com.youpackage:background_crash I/DynamiteModule: Considering local module com.google.android.gms.flags:0 and remote module com.google.android.gms.flags:1
com.youpackage:background_crash I/DynamiteModule: Selected remote version of com.google.android.gms.flags, version >= 1
com.youpackage:background_crash D/FirebaseCrashReceiverServiceImpl: Saving crash
com.youpackage:background_crash I/FirebaseCrashSenderServiceImpl: FirebaseCrashSenderServiceImpl created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/user/0/com.google.android.gms/app_chimera/m/00000005/DynamiteModulesC_GmsCore_prodmnc_xxhdpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000005/n/armeabi-v7a, /data/user/0/com.google.android.gms/app_chimera/m/00000005/n/armeabi, /vendor/lib, /system/lib]]]
D/FirebaseCrashSenderServiceImpl: Response code: 200
D/FirebaseCrashSenderServiceImpl: Report sent
You can check the Crash reports on Console by logging into https://console.firebase.google.com in crash reports will look like this
Cheers!!
References :
https://firebase.google.com/docs/android
No comments:
Post a Comment