Skip to content

Commit

Permalink
Merge pull request #286 from boostcampwm-2022/chore/buildSrc
Browse files Browse the repository at this point in the history
buildSrc 에서 version catalog 방식으로 변경
  • Loading branch information
audxo112 authored Feb 6, 2023
2 parents c79831d + 3b14e85 commit 795ba8e
Show file tree
Hide file tree
Showing 29 changed files with 876 additions and 581 deletions.
76 changes: 41 additions & 35 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,46 +1,26 @@
@file:Suppress("UnstableApiUsage")

import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
kotlin("kapt")
id("dagger.hilt.android.plugin")
id("com.google.android.gms.oss-licenses-plugin")
id("beep.android.application")
id("beep.android.hilt")
alias(libs.plugins.ksp)
}

android {
namespace = "com.lighthouse.beep"
compileSdk = AppConfig.compileSdk
buildToolsVersion = AppConfig.buildToolsVersion

defaultConfig {
applicationId = "com.lighthouse.beep"
minSdk = AppConfig.minSdk
targetSdk = AppConfig.targetSdk
versionCode = AppConfig.versionCode
versionName = AppConfig.versionName

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
versionCode = 1
versionName = "1.0.0"

buildConfigField("String", "kakaoSearchId", getApiKey("kakao_search_id"))
manifestPlaceholders["naver_map_api_id"] = getApiKey("naver_map_api_id")
}

buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = AppConfig.jvmTarget
}
buildFeatures {
dataBinding = true
}
Expand All @@ -51,13 +31,39 @@ android {
}

dependencies {
implementation(project(":domain"))
implementation(project(":presentation"))
implementation(project(":data"))
implementation(platform(Libraries.FIREBASE_BOM))
kapt(Kapt.APP_LIBRARIES)
implementation(Libraries.APP_LIBRARIES)
annotationProcessor(AnnotationProcessors.APP_LIBRARIES)
implementation(projects.domain)
implementation(projects.presentation)
implementation(projects.data)

implementation(libs.androidX.hilt.work)
implementation(libs.androidX.work.runtime.ktx)
implementation(libs.androidX.room.ktx)
implementation(libs.androidX.room.runtime)
implementation(libs.androidX.datastore.preferences)

implementation(libs.kotlin.coroutine.core)
implementation(libs.kotlin.coroutine.android)

implementation(libs.squareup.retrofit2)
implementation(libs.squareup.retrofit2.converter.moshi)
implementation(libs.squareup.moshi.kotlin)
implementation(libs.squareup.moshi.adapters)

implementation(platform(libs.firebase.bom))
implementation(libs.firebase.auth.ktx)

implementation(libs.gms.play.services.oss.licences)

implementation(libs.timber)

ksp(libs.androidX.room.compiler)
ksp(libs.glide.ksp)

testImplementation(libs.junit4)
}

kapt {
useBuildCache = true
}

fun getApiKey(propertyKey: String): String {
Expand Down
21 changes: 10 additions & 11 deletions app/src/main/java/com/lighthouse/BeepApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@ package com.lighthouse
import android.app.Application
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import com.lighthouse.beep.BuildConfig
import com.lighthouse.presentation.background.BeepWorkManager
import com.lighthouse.utils.log.ComponentLogger
import com.lighthouse.utils.log.CustomTimberTree
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber
import javax.inject.Inject

@HiltAndroidApp
class BeepApplication : Application(), Configuration.Provider {

@Inject
lateinit var componentLogger: ComponentLogger

@Inject
lateinit var customTimberTree: CustomTimberTree

@Inject
lateinit var workerFactory: HiltWorkerFactory

override fun onCreate() {
super.onCreate()

if (BuildConfig.DEBUG) {
Timber.plant(CustomTimberTree())
}
Timber.plant(customTimberTree)
componentLogger.initialize(this)

BeepWorkManager(this)
}
Expand All @@ -30,9 +35,3 @@ class BeepApplication : Application(), Configuration.Provider {
.setWorkerFactory(workerFactory)
.build()
}

class CustomTimberTree : Timber.DebugTree() {
override fun createStackElementTag(element: StackTraceElement): String {
return "${element.className}:${element.lineNumber}#${element.methodName}"
}
}
146 changes: 146 additions & 0 deletions app/src/main/java/com/lighthouse/utils/log/ComponentLogger.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package com.lighthouse.utils.log

import android.app.Activity
import android.app.Application
import android.content.Context
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import timber.log.Timber
import javax.inject.Inject

private const val loggerTag = "Logger"

private inline val <T : Any> T.javaClassName: String
get() = javaClass.name

private fun Fragment.printLifecycle(lifecycleScope: String) {
Timber.tag(loggerTag).d("[Fragment] $lifecycleScope - $javaClassName(${hashCode()})")
}

private fun Activity.printLifecycle(lifecycleScope: String) {
Timber.tag(loggerTag).d("[Activity] $lifecycleScope - $javaClassName(${hashCode()})")
}

class ComponentLogger @Inject constructor() {
fun initialize(application: Application) {
application.registerActivityLifecycleCallbacks(
object : Application.ActivityLifecycleCallbacks {
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
activity.printLifecycle("onCreate")
handleActivity(activity)
}

override fun onActivityStarted(activity: Activity) {
activity.printLifecycle("onStart")
}

override fun onActivityResumed(activity: Activity) {
activity.printLifecycle("onResume")
}

override fun onActivityPaused(activity: Activity) {
activity.printLifecycle("onPause")
}

override fun onActivityStopped(activity: Activity) {
activity.printLifecycle("onStop")
}

override fun onActivitySaveInstanceState(
activity: Activity,
savedInstanceState: Bundle
) {
activity.printLifecycle("onSaveInstance")
}

override fun onActivityDestroyed(activity: Activity) {
activity.printLifecycle("onDestroy")
}
}
)
}

private fun handleActivity(activity: Activity) {
if (activity is FragmentActivity) {
activity.supportFragmentManager.registerFragmentLifecycleCallbacks(
object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentAttached(
fm: FragmentManager,
f: Fragment,
context: Context
) {
super.onFragmentAttached(fm, f, context)
f.printLifecycle("onAttach")
}

override fun onFragmentCreated(
fm: FragmentManager,
f: Fragment,
savedInstanceState: Bundle?
) {
super.onFragmentCreated(fm, f, savedInstanceState)
f.printLifecycle("onCreate")
}

override fun onFragmentViewCreated(
fm: FragmentManager,
f: Fragment,
v: View,
savedInstanceState: Bundle?
) {
super.onFragmentViewCreated(fm, f, v, savedInstanceState)
f.printLifecycle("onViewCreated")
}

override fun onFragmentStarted(fm: FragmentManager, f: Fragment) {
super.onFragmentStarted(fm, f)
f.printLifecycle("onStart")
}

override fun onFragmentResumed(fm: FragmentManager, f: Fragment) {
super.onFragmentResumed(fm, f)
f.printLifecycle("onResume")
}

override fun onFragmentPaused(fm: FragmentManager, f: Fragment) {
super.onFragmentPaused(fm, f)
f.printLifecycle("onPause")
}

override fun onFragmentStopped(fm: FragmentManager, f: Fragment) {
super.onFragmentStopped(fm, f)
f.printLifecycle("onStop")
}

override fun onFragmentSaveInstanceState(
fm: FragmentManager,
f: Fragment,
outState: Bundle
) {
super.onFragmentSaveInstanceState(fm, f, outState)
f.printLifecycle("onSaveInstance")
}

override fun onFragmentViewDestroyed(fm: FragmentManager, f: Fragment) {
super.onFragmentViewDestroyed(fm, f)
f.printLifecycle("onViewDestroy")
}

override fun onFragmentDestroyed(fm: FragmentManager, f: Fragment) {
super.onFragmentDestroyed(fm, f)
f.printLifecycle("onDestroy")
}

override fun onFragmentDetached(fm: FragmentManager, f: Fragment) {
super.onFragmentDetached(fm, f)
f.printLifecycle("onDetach")
}
},
true
)
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/java/com/lighthouse/utils/log/CustomTimberTree.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.lighthouse.utils.log

import timber.log.Timber
import javax.inject.Inject

class CustomTimberTree @Inject constructor() : Timber.DebugTree() {
override fun createStackElementTag(element: StackTraceElement): String {
return "${element.className}:${element.lineNumber}#${element.methodName}"
}
}
1 change: 1 addition & 0 deletions build-logic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
1 change: 1 addition & 0 deletions build-logic/convention/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
45 changes: 45 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
plugins {
`kotlin-dsl` // enable the Kotlin-DSL
}

group = "com.lighthouse.beep.buildlogic"

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.hilt.gradlePlugin)
}

gradlePlugin {
plugins {
register("androidApplication") {
id = "beep.android.application"
implementationClass = "AndroidApplicationConventionPlugin"
}
register("androidApplicationCompose") {
id = "beep.android.application.compose"
implementationClass = "AndroidApplicationComposeConventionPlugin"
}
register("androidLibrary") {
id = "beep.android.library"
implementationClass = "AndroidLibraryConventionPlugin"
}
register("androidLibraryCompose") {
id = "beep.android.library.compose"
implementationClass = "AndroidLibraryComposeConventionPlugin"
}
register("androidHilt") {
id = "beep.android.hilt"
implementationClass = "AndroidHiltConventionPlugin"
}
register("javaLibrary") {
id = "beep.java.library"
implementationClass = "JavaLibraryConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import com.lighthouse.convention.configureAndroidCompose
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType

class AndroidApplicationComposeConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("com.android.application")
val extension = extensions.getByType<BaseAppModuleExtension>()
configureAndroidCompose(extension)
}
}
}
Loading

0 comments on commit 795ba8e

Please sign in to comment.