Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Firebase Setup #77

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ plugins {
}

apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
import com.android.build.OutputFile

/**
Expand Down Expand Up @@ -208,14 +210,12 @@ android {
productFlavors {
ph {
versionName defaultConfig.versionName + "-ph"
buildConfigField "boolean", "ENABLE_LOG", "true"
manifestPlaceholders = [
APP_NAME: APP_NAME_PH
]
dimension "mosip"
}
newlogic {
buildConfigField "boolean", "ENABLE_LOG", "false"
versionName defaultConfig.versionName + "-newlogic"
manifestPlaceholders = [
APP_NAME: APP_NAME_NEWLOGIC
Expand All @@ -235,7 +235,7 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "com.facebook.react:react-native:+"// From node_modules

def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";
def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";
Expand Down Expand Up @@ -280,6 +280,10 @@ dependencies {
} else {
implementation jscFlavor
}
// Firebase
implementation 'com.google.firebase:firebase-crashlytics:17.3.1'
implementation 'com.google.firebase:firebase-analytics:18.0.2'
implementation 'com.jakewharton.timber:timber:4.7.1'
}

// Run this once to be able to run the application with BUCK
Expand All @@ -292,3 +296,12 @@ task copyDownloadableDepsToLibs(type: Copy) {
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
applyNativeModulesAppBuildGradle(project)
apply from: "./eas-build.gradle"

try {
def servicesJSON = file('google-services.json')
if (servicesJSON.text) {
apply plugin: 'com.google.gms.google-services'
}
} catch(Exception e) {
logger.warn("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}
39 changes: 39 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "259470317171",
"project_id": "mosip-resident-app",
"storage_bucket": "mosip-resident-app.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:259470317171:android:56cabc5c523dfbed88fc06",
"android_client_info": {
"package_name": "io.mosip.residentapp"
}
},
"oauth_client": [
{
"client_id": "259470317171-rbr3qet1r24n05ojj3u7h734jkp84514.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyBnCTpF1_1N4YFWZeAVGsndKJNCwnICQ6Q"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "259470317171-rbr3qet1r24n05ojj3u7h734jkp84514.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;
import android.util.Log;

import androidx.annotation.NonNull;

import com.facebook.react.PackageList;
Expand All @@ -14,8 +16,11 @@

import expo.modules.ApplicationLifecycleDispatcher;
import expo.modules.ReactNativeHostWrapper;
import timber.log.Timber;

import com.facebook.react.bridge.JSIModulePackage;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.crashlytics.FirebaseCrashlytics;
import com.swmansion.reanimated.ReanimatedJSIModulePackage;

import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -62,6 +67,13 @@ public void onCreate() {

initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
ApplicationLifecycleDispatcher.onApplicationCreate(this);

if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
}
// Setup Firebase
FirebaseAnalytics.getInstance(this);
Timber.plant(new CrashReportingTree());
}

@Override
Expand Down Expand Up @@ -100,4 +112,26 @@ private static void initializeFlipper(
}
}
}
/**
* A tree which logs important information for crash reporting.
*/
private static class CrashReportingTree extends Timber.Tree {
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
@Override
protected void log(int priority, String tag, @NonNull String message, Throwable t) {
if (priority == Log.VERBOSE || priority == Log.DEBUG) {
return;
}

crashlytics.setCustomKey("priority", priority);
crashlytics.setCustomKey("tag", tag);
crashlytics.log(message);

if (t != null) {
if (priority == Log.ERROR) {
crashlytics.recordException(t);
}
}
}
}
}
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ buildscript {
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down