@janiscommerce/app-crashlytics
v2.1.0
Published
Crashlytics methods for janis apps
Downloads
99
Maintainers
Readme
@janiscommerce/app-crashlytics
Library of methods to report when the app crashes.
Firebase setting
Before getting started, you should have set up a new firebase project.
If you already have it set up, the next step to do would be to add the google-services.json file to the root directory of your module (/android/app).
Add the firebase sdk
For the Firebase SDKs to be able to access the google-services.json configuration values, you need the Google Services Gradle plugin.
Add the plugin as a dependency to your project-level build.gradle file: (android/build.gradle)
dependencies {
// ...
classpath("com.google.gms:google-services:4.3.15")
classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.9")
}
You should also add google services plugins in android/app/build.gradle and any Firebase SDKs you want to use in your app:
plugins {
// ...
// Add the Google services Gradle plugin
id("com.google.gms.google-services")
id("com.google.firebase.crashlytics")
}
dependencies {
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:32.2.2')
// Add the dependencies for any other desired Firebase products
// https://firebase.google.com/docs/android/setup#available-libraries
}
// Additionally you should make one optional configuration
// It reporting allows you to capture Native Development Kit crashes,
// e.g. in React Native this will capture crashes originating from the Yoga layout engine
android {
// ...
buildTypes {
// ...
release {
// ...
firebaseCrashlytics {
nativeSymbolUploadEnabled true
unstrippedNativeLibsDir 'build/intermediates/merged_native_libs/release/out/lib'
}
}
}
}
You may need to add this in android/settings.gradle:
// ...
include ':@react-native-firebase_app'
project(':@react-native-firebase_app').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/app/android')
Add the firebase file configuration
Add the firebase.json file to the root of your project, with:
{
"react-native": {
"crashlytics_debug_enabled": true,
}
}
Clean the project
cd android && ./gradlew clean && cd ..
PeerDependencies Installation
For the methods of this library to work, the following dependencies must be installed:
npm install @react-native-firebase/app
The @react-native-firebase/app module must be installed before using any other Firebase service.
Additionally, you need to install the dependency of the firebase service you want to use. For example this:
npm install @react-native-firebase/crashlytics
This dependency will allow that, when executing the methods of the package, these can be registered as events in firebase
Installation
npm install @janis-commerce/app-crashlytics
Usage
Functions
initialize() ⇒ void
initalize data from userData
Kind: global function
Example
import Crashlytics from '@janiscommerce/app-crashlytics'
const crash = new Crashlytics()
// minimum example
crash.initialize()
crashThisApp() ⇒ void
Cause your app to crash for testing purposes
Kind: global function
Example
import Crashlytics from '@janiscommerce/app-crashlytics'
const crash = new Crashlytics()
// minimum example
crash.crashThisApp()
recordError(error, jsErrorName, attributes) ⇒ void
Record a JavaScript Error.
Kind: global function
Throws:
- An error when some required params is not passed
| Param | Type | Description | | --- | --- | --- | | error | Error | Javascript error | | jsErrorName | string | undefined | Error name | | attributes | object | Attributes that can be either a string or an object. |
Example
import Crashlytics from '@janiscommerce/app-crashlytics'
const crash = new Crashlytics()
// without params
const error = throw Error('params are required');
crash.recordError(error, 'error-name')
// with params
const error = throw Error('params are required');
crash.recordError(error, 'error-name', {name: Pepe})
log(message, attributes, attributes[attributes) ⇒ void
Log a message that will appear in any subsequent Crash or Non-fatal error reports
Kind: global function
Throws:
- An error when some required params is not passed
| Param | Type | Description | | --- | --- | --- | | message | string | Context message. | | attributes | object | Attributes. | | attributes.userIdAattribute | string | User Id. | | attributes.error | Error | Attribute to error records. | | attributes[attributes | string | object | Attributes that can be either a string or an object. |
Example
import Crashlytics from '@janiscommerce/app-crashlytics'
const crash = new Crashlytics()
// minimum example
crash.log('this is a pda error')
// add userId to crashlytics console
crash.log('this is a pda error', {userId: '213213})
// recod an error to crashlytics console
crash.log('this is a pda error', {error: Error})
// add an attribute to crashlytics console
crash.log('this is a pda error', {name: 'Pedro'})
// add attributes to crashlytics console
crash.log('this is a pda error', {info: {name: 'Pedro', email: '[email protected]', age: '38'}})