Skip to content

Commit

Permalink
Added Firebase Analytics and signing configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriy-chernysh committed Apr 22, 2024
1 parent eb1e4e7 commit 97059a5
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 2 deletions.
43 changes: 43 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import com.android.build.gradle.AppExtension
import java.io.FileNotFoundException
import java.util.Properties

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("com.android.application")
kotlin("android")
kotlin("kapt")

alias(libs.plugins.google.services)
alias(libs.plugins.crashlytics)
alias(libs.plugins.performance.monitor)
}

android {
Expand All @@ -26,6 +32,22 @@ android {
}
}

signingConfigs {
val keystoreProperties = Properties()
try {
keystoreProperties.load(File(rootDir, "keystore.properties").inputStream())

create("release") {
storeFile = file("release.jks")
storePassword = keystoreProperties["KSTOREPWD"] as String
keyAlias = keystoreProperties["KEYSTORE_ALIAS"] as String
keyPassword = keystoreProperties["KEYPWD"] as String
}
} catch (e: FileNotFoundException) {
println("Warning: keystore.properties file not found.")
}
}

buildTypes {
getByName("debug") {
isDebuggable = true
Expand All @@ -36,6 +58,12 @@ android {
isMinifyEnabled = true
isShrinkResources = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
signingConfig = try {
signingConfigs.getByName("release")
} catch (e: UnknownDomainObjectException) {
println("SigningConfig with not found. Skipping...")
null
}
}
}

Expand All @@ -50,6 +78,7 @@ android {
create("dev") {
dimension = "default"
applicationIdSuffix = ".apptemplate.compose"
isDefault = true
}
}

Expand Down Expand Up @@ -82,7 +111,21 @@ dependencies {

implementation(projects.core.navigation)

implementation(libs.firebase.performance)
implementation(projects.core.analytics)

testApi(libs.bundles.test.common)

// Exclude Firebase from your Android tests due to errors "Could not resolve all files for configuration"
androidTestImplementation(libs.firebase.performance) {
exclude(group = "com.google.firebase", module = "firebase-perf")
}
androidTestImplementation(libs.firebase.analytics) {
exclude(group = "com.google.firebase", module = "firebase-analytics")
}
androidTestImplementation(libs.firebase.crashlytics) {
exclude(group = "com.google.firebase", module = "firebase-crashlytics")
}
}


Expand Down
48 changes: 48 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"project_info": {
"project_number": "893380205579",
"project_id": "close-talk-app-android",
"storage_bucket": "close-talk-app-android.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:893380205579:android:74571fe1c67478b0d97b0e",
"android_client_info": {
"package_name": "com.mobiledevpro.apptemplate.compose"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyBjppGln1CyNvS_zWDdF1g3m3OmtEpJyxg"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:893380205579:android:9fe82812e5a3bc79d97b0e",
"android_client_info": {
"package_name": "com.mobiledevpro.closetalk.app"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyBjppGln1CyNvS_zWDdF1g3m3OmtEpJyxg"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
4 changes: 4 additions & 0 deletions build-logic/src/main/kotlin/feature-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ dependencies {
implementation(project(":core:di"))
implementation(project(":core:domain"))
implementation(project(":core:coroutines"))
implementation(project(":core:util"))

implementation(libs.bundle("lifecycle"))
implementation(libs.library("coil"))
implementation(libs.library("activity.ktx"))

//Crashlytics
implementation(project(":core:analytics"))
}
1 change: 1 addition & 0 deletions core/analytics/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
10 changes: 10 additions & 0 deletions core/analytics/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id("core-module")
}

dependencies {
implementation(platform(libs.firebase.bom))
api(libs.firebase.analytics)
api(libs.firebase.crashlytics)
api(libs.firebase.performance)
}
Empty file.
21 changes: 21 additions & 0 deletions core/analytics/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
2 changes: 2 additions & 0 deletions core/analytics/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2023 | Dmitri Chernysh | https://mobile-dev.pro
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.mobiledevpro.analytics


object AnalyticsEvent {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2023 | Dmitri Chernysh | https://mobile-dev.pro
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.mobiledevpro.analytics

import android.util.Log
import com.google.firebase.crashlytics.FirebaseCrashlytics


object Crashlytics {
fun log(message: String) {
Log.d("Crashlytics", message)
FirebaseCrashlytics.getInstance().log(message)
}

fun log(logLevel: Int, logTag: String, message: String) {
val log: String = when (logLevel) {
Log.ERROR -> {
Log.e(logTag, message)
"E/$logTag: "
}

Log.INFO -> {
Log.i(logTag, message)
"I/$logTag: "
}

else -> {
Log.d(logTag, message)
"D/$logTag: "
}
}

FirebaseCrashlytics.getInstance().log(log + message)
}

fun logException(throwable: Throwable) {
Log.e("Crashlytics", throwable.localizedMessage, throwable)
FirebaseCrashlytics.getInstance().recordException(throwable)
}

fun setCustomKey(key: String, value: String) {
FirebaseCrashlytics.getInstance()
.setCustomKey(key, value)
}
}
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ firebase-crashlytics = { module = "com.google.firebase:firebase-crashlytics" }
firebase-analytics = { module = "com.google.firebase:firebase-analytics" }
firebase-performance = { module = "com.google.firebase:firebase-perf" }
firebase-messaging = { module = "com.google.firebase:firebase-messaging" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }


[bundles]
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ include(":feature:people_profile")
include(":feature:people")
include(":core:di")
include(":core:util")
include(":core:analytics")

0 comments on commit 97059a5

Please sign in to comment.