Skip to content

Commit

Permalink
UPDATE: Migrate Fabric Crashlytics to Firebase Crashlytics.
Browse files Browse the repository at this point in the history
FirebaseServiceProxy is removed, as Firebase Crashlytics is apparently working in China now.
  • Loading branch information
oasisfeng committed Oct 17, 2020
1 parent ea43a85 commit 0002ce8
Showing 7 changed files with 23 additions and 86 deletions.
8 changes: 5 additions & 3 deletions assembly/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

android {
compileSdkVersion this.compileSdkVersion
@@ -14,6 +16,9 @@ android {
buildFeatures.dataBinding true

buildTypes {
debug {
firebaseCrashlytics.mappingFileUploadEnabled false
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
@@ -76,6 +81,3 @@ dependencies {
// File Provider only
fileproviderImplementation project(':fileprovider')
}

// Firebase plug-in
apply plugin: 'com.google.gms.google-services'
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.google.gms:google-services:4.3.4'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.3.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
11 changes: 3 additions & 8 deletions shared/build.gradle
Original file line number Diff line number Diff line change
@@ -10,13 +10,8 @@ android {
}

buildTypes {
release {
buildConfigField("boolean", "CRASHLYTICS_ENABLED", "true")
}
debug {
ext.enableCrashlytics = false
buildConfigField("boolean", "CRASHLYTICS_ENABLED", "${ext.enableCrashlytics}")
}
release { buildConfigField("boolean", "CRASHLYTICS_ENABLED", "true") }
debug { buildConfigField("boolean", "CRASHLYTICS_ENABLED", "false") }
}

kotlinOptions.jvmTarget = "1.8"
@@ -54,7 +49,7 @@ dependencies {
implementation 'com.google.firebase:firebase-core:17.5.1'
implementation 'com.google.firebase:firebase-analytics:17.6.0'
implementation 'com.google.firebase:firebase-config:19.2.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
implementation 'com.oasisfeng.condom:library:2.5.0'
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.10.0'
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
import android.app.Application;

import com.oasisfeng.island.analytics.CrashReport;
import com.oasisfeng.island.firebase.FirebaseServiceProxy;
import com.oasisfeng.island.shared.R;

/**
* For singleton instance purpose only.
@@ -23,11 +21,5 @@ public IslandApplication() {
CrashReport.initCrashHandler();
}

@Override public void onCreate() {
super.onCreate();
final String firebase_proxy_host = getString(R.string.firebase_proxy_host);
if (! firebase_proxy_host.isEmpty()) FirebaseServiceProxy.initialize(firebase_proxy_host);
}

private static IslandApplication sInstance;
}
Original file line number Diff line number Diff line change
@@ -2,14 +2,13 @@

import android.os.Process;

import com.crashlytics.android.core.CrashlyticsCore;
import androidx.annotation.NonNull;

import com.google.firebase.crashlytics.FirebaseCrashlytics;
import com.oasisfeng.android.util.Suppliers;
import com.oasisfeng.island.firebase.FirebaseWrapper;
import com.oasisfeng.island.shared.BuildConfig;

import java.util.function.Supplier;

import io.fabric.sdk.android.Fabric;

/**
* Lazy initializer for crash handler.
@@ -18,32 +17,28 @@
*/
public abstract class CrashReport {

private static final boolean DISABLED = BuildConfig.DEBUG && ! BuildConfig.CRASHLYTICS_ENABLED;

static void logException(final Throwable t) { sSingleton.get().logException(t); }
static void logException(final Throwable t) { sSingleton.get().recordException(t); }
static void log(final String message) { sSingleton.get().log(message); }
static void setProperty(final String key, final String value) { sSingleton.get().setString(key, value); }
static void setProperty(final String key, final int value) { sSingleton.get().setInt(key, value); }
static void setProperty(final String key, final boolean value) { sSingleton.get().setBool(key, value); }

private static final Supplier<CrashlyticsCore> sSingleton = Suppliers.memoize(() -> {
Fabric.with(new Fabric.Builder(FirebaseWrapper.init()).debuggable(BuildConfig.DEBUG)
.kits(new CrashlyticsCore.Builder().disabled(DISABLED).build()).build());
final CrashlyticsCore instance = CrashlyticsCore.getInstance();
instance.setInt("user", Process.myUserHandle().hashCode()); // Attach the current (Android) user ID to crash report.
return instance;
static void setProperty(final String key, final String value) { sSingleton.get().setCustomKey(key, value); }
static void setProperty(final String key, final int value) { sSingleton.get().setCustomKey(key, value); }
static void setProperty(final String key, final boolean value) { sSingleton.get().setCustomKey(key, value); }

private static final Supplier<FirebaseCrashlytics> sSingleton = Suppliers.memoize(() -> {
final FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
crashlytics.setCrashlyticsCollectionEnabled(true/*BuildConfig.CRASHLYTICS_ENABLED*/);
crashlytics.setCustomKey("user", Process.myUserHandle().hashCode()); // Attach the current (Android) user ID to crash report.
return crashlytics;
});

public static void initCrashHandler() {
if (DISABLED) return;
final Thread.UncaughtExceptionHandler current_exception_handler = Thread.getDefaultUncaughtExceptionHandler();
if (! (current_exception_handler instanceof LazyThreadExceptionHandler))
Thread.setDefaultUncaughtExceptionHandler(new LazyThreadExceptionHandler(current_exception_handler));
}

private static class LazyThreadExceptionHandler implements Thread.UncaughtExceptionHandler {

@Override public void uncaughtException(final Thread thread, final Throwable e) {
@Override public void uncaughtException(final @NonNull Thread thread, final @NonNull Throwable e) {
if (mHandlingUncaughtException) { // Avoid infinite recursion
mOriginalHandler.uncaughtException(thread, e);
return;

This file was deleted.

4 changes: 0 additions & 4 deletions shared/src/main/res/values/values.xml

This file was deleted.

0 comments on commit 0002ce8

Please sign in to comment.