Skip to content

Commit 087b641

Browse files
authored
Merge pull request #508 from AppDevNext/UsageWithoutFirebase
Prevent crash in usage without Firebase in Demo
2 parents 7b9078e + 7f90eb1 commit 087b641

4 files changed

Lines changed: 32 additions & 7 deletions

File tree

build.gradle

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,22 @@ static def getTag() {
4747
return process.text.toString().trim()
4848
}
4949

50+
@SuppressWarnings('unused')
51+
static def useFirebase() {
52+
def process = "grep DUMMYKEY sample/google-services.json -R | wc -c".execute()
53+
def grepResult = process.text.toString().split(":")[1].toInteger()
54+
if (grepResult == 1) {
55+
println("Firebase=false $grepResult")
56+
return "false"
57+
}
58+
else {
59+
println("Firebase=true $grepResult")
60+
return "true"
61+
}
62+
}
63+
5064
@SuppressWarnings('unused')
5165
static def getGitCommitCount() {
52-
def process = "git rev-list HEAD --count".execute()
53-
return process.text.toInteger()
66+
def process = "git describe --tags --abbrev=0".execute()
67+
return process.text.toString().trim()
5468
}

sample/build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
plugins {
22
id 'com.android.application'
33
id 'kotlin-android'
4-
id 'com.google.gms.google-services'
5-
id 'com.google.firebase.crashlytics'
4+
// id 'com.google.gms.google-services'
5+
// id 'com.google.firebase.crashlytics'
6+
}
7+
8+
if (useFirebase() == "true") {
9+
apply plugin: 'com.google.gms.google-services'
10+
apply plugin: 'com.google.firebase.crashlytics'
611
}
712

813
android {
@@ -16,6 +21,8 @@ android {
1621
minSdkVersion 16
1722
targetSdkVersion 33
1823

24+
buildConfigField "boolean", 'WITH_FIREBASE', useFirebase()
25+
1926
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2027
testInstrumentationRunnerArguments useTestStorageService: 'true'
2128
}

sample/google-services.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"project_info": {
3-
"project_number": "1234",
3+
"project_number": "DUMMYKEY",
44
"firebase_url": "https://liveedgedetection.firebaseio.com",
55
"project_id": "liveedgedetection",
66
"storage_bucket": "liveedgedetection.appspot.com"

sample/src/main/java/info/hannes/logcat/sample/CrashlyticApplication.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ class CrashlyticApplication : LoggingApplication() {
3636
}
3737
}
3838

39-
FirebaseCrashlytics.getInstance().setCustomKey("VERSION_NAME", info.hannes.logcat.ui.BuildConfig.VERSIONNAME)
40-
Timber.plant(CrashlyticsTree(Settings.Secure.getString(applicationContext.contentResolver, Settings.Secure.ANDROID_ID)))
39+
if (BuildConfig.WITH_FIREBASE) {
40+
Timber.i("I use Firebase")
41+
FirebaseCrashlytics.getInstance().setCustomKey("VERSION_NAME", info.hannes.logcat.ui.BuildConfig.VERSIONNAME)
42+
Timber.plant(CrashlyticsTree(Settings.Secure.getString(applicationContext.contentResolver, Settings.Secure.ANDROID_ID)))
43+
} else
44+
Timber.w("No valid Firebase key was given")
4145

4246
Timber.d("Debug test")
4347
Timber.i("Info test")

0 commit comments

Comments
 (0)