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

DEP-364 config: debug, release 환경별로 변수 분리 #185

Merged
merged 10 commits into from
Jan 9, 2023
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- run: echo $LOCAL_PROPERTIES_FILE | base64 -d > local.properties
env:
LOCAL_PROPERTIES_FILE: ${{ secrets.LOCAL_PROPERTIES_FILE }}
- name: Build and analyze
uses: gradle/gradle-build-action@v2
env:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
- run: echo $DEBUG_KEYSTORE_FILE | base64 -d > debug.keystore
env:
DEBUG_KEYSTORE_FILE: ${{ secrets.DEBUG_KEYSTORE_FILE }}
- run: echo $LOCAL_PROPERTIES_FILE | base64 -d > local.properties
env:
LOCAL_PROPERTIES_FILE: ${{ secrets.LOCAL_PROPERTIES_FILE }}
- name: Build
run: chmod +x ./gradlew && ./gradlew :app::assembleAlpha --quiet
env:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ captures/

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore
*.jks
*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
Expand Down
18 changes: 18 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ plugins {
id 'com.google.firebase.crashlytics'
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

android {
compileSdk 33

Expand All @@ -24,6 +27,7 @@ android {
}

signingConfigs {
// GitHub Action 으로 빌드, 배포할 때 사용함
ciDebug {
storeFile file("$project.rootDir/debug.keystore")
storePassword System.getenv('DEBUG_STORE_PASSWORD')
Expand All @@ -36,6 +40,19 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
manifestPlaceholders = [
KAKAO_APP_KEY: properties.getProperty('release.kakao.app-key')
]
buildConfigField 'String', 'BASE_URL', "\"${properties.getProperty('release.three-days.base-url')}\""
buildConfigField 'String', 'KAKAO_APP_KEY', "\"${properties.getProperty('release.kakao.app-key')}\""
}
debug {
applicationIdSuffix '.debug'
manifestPlaceholders = [
KAKAO_APP_KEY: properties.getProperty('debug.kakao.app-key')
]
buildConfigField 'String', 'BASE_URL', "\"${properties.getProperty('debug.three-days.base-url')}\""
buildConfigField 'String', 'KAKAO_APP_KEY', "\"${properties.getProperty('debug.kakao.app-key')}\""
}
alpha {
initWith debug
Expand All @@ -57,6 +74,7 @@ android {
dependencies {
implementation(project(":domain"))
implementation(project(":data"))
implementation(project(":build-property"))
implementation(project(":core"))
implementation(project(":navigator"))
implementation(project(":presentation:home"))
Expand Down
39 changes: 39 additions & 0 deletions app/src/alpha/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "1091459842156",
"project_id": "three-days-develop",
"storage_bucket": "three-days-develop.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:1091459842156:android:8f8abdfe99c268fe485849",
"android_client_info": {
"package_name": "com.depromeet.threedays.debug"
}
},
"oauth_client": [
{
"client_id": "1091459842156-pjhtgjo35d6ro1ra922ngi7aabealvsc.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyB0EiDGdeC8Oxa9HvFshjg0YCZrfhzY4cs"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1091459842156-pjhtgjo35d6ro1ra922ngi7aabealvsc.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
39 changes: 39 additions & 0 deletions app/src/debug/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "1091459842156",
"project_id": "three-days-develop",
"storage_bucket": "three-days-develop.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:1091459842156:android:8f8abdfe99c268fe485849",
"android_client_info": {
"package_name": "com.depromeet.threedays.debug"
}
},
"oauth_client": [
{
"client_id": "1091459842156-pjhtgjo35d6ro1ra922ngi7aabealvsc.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyB0EiDGdeC8Oxa9HvFshjg0YCZrfhzY4cs"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1091459842156-pjhtgjo35d6ro1ra922ngi7aabealvsc.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
File renamed without changes.
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@
<category android:name="android.intent.category.BROWSABLE" />

<!-- Redirect URI: "kakao${NATIVE_APP_KEY}://oauth" -->
<data android:host="oauth"
android:scheme="kakaof0c0458b5837b0f245c73b5a22908319" />
<data
android:host="oauth"
android:scheme="kakao${KAKAO_APP_KEY}" />
</intent-filter>
</activity>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package com.depromeet.threedays

import android.app.Application
import com.depromeet.threedays.buildproperty.BuildProperty
import com.depromeet.threedays.buildproperty.BuildPropertyRepository
import com.depromeet.threedays.core.analytics.AnalyticsUtil
import com.kakao.sdk.common.KakaoSdk
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber
import javax.inject.Inject

@HiltAndroidApp
class ThreeDaysApplication : Application() {
@Inject
lateinit var buildPropertyRepository: BuildPropertyRepository

override fun onCreate() {
super.onCreate()

Expand All @@ -21,7 +27,10 @@ class ThreeDaysApplication : Application() {
}

private fun initKakaoSdk() {
KakaoSdk.init(this, "f0c0458b5837b0f245c73b5a22908319")
KakaoSdk.init(
context = this,
appKey = buildPropertyRepository.get(BuildProperty.KAKAO_APP_KEY),
)
}

private fun initAnalytics() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import com.depromeet.threedays.domain.usecase.notification.token.UpdateNotificat
import com.depromeet.threedays.home.MainActivity
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import kotlinx.coroutines.runBlocking
import timber.log.Timber
import javax.inject.Inject
import com.depromeet.threedays.core_design_system.R as CoreDesignSystemResources

Expand All @@ -25,18 +23,6 @@ class FCMService @Inject constructor() : FirebaseMessagingService() {
override fun onNewToken(token: String) {
super.onNewToken(token)
Log.i(TAG, "onNewToken: $token")
try {
// FIXME:
// - useCase initialize 안되었다는 에러 발생함.
// - 앱 처음 설치하면 스플래시 화면에서 호출되는데 이 때 memberId 없음
runBlocking {
updateNotificationTokenUseCase(token)
}
} catch (e: Exception) {
Timber.w(
e, "Failed to update fcm registration token"
)
}
}

override fun onMessageReceived(message: RemoteMessage) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.depromeet.threedays.property

import com.depromeet.threedays.buildproperty.BuildPropertyRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
class BuildPropertyModule {

@Singleton
@Provides
fun bindsBuildPropertyRepositoryProvide(
buildPropertyRepositoryImpl: BuildPropertyRepositoryImpl,
): BuildPropertyRepository = buildPropertyRepositoryImpl
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.depromeet.threedays.property

import com.depromeet.threedays.BuildConfig
import com.depromeet.threedays.buildproperty.BuildProperty
import com.depromeet.threedays.buildproperty.BuildPropertyRepository
import timber.log.Timber
import javax.inject.Inject

class BuildPropertyRepositoryImpl @Inject constructor() : BuildPropertyRepository {
override fun get(buildProperty: BuildProperty): String {
try {
return readProperties(buildProperty = buildProperty)
} catch (e: Exception) {
throw IllegalStateException(
"Failed to read property from local.properties. key: $buildProperty",
e
)
}
}

override fun getOrNull(buildProperty: BuildProperty): String? {
return try {
readProperties(buildProperty = buildProperty)
} catch (e: Exception) {
Timber.e(e, "Failed to read property from local.properties. key: $buildProperty")
null
}
}

private fun readProperties(buildProperty: BuildProperty): String {
return BuildConfig::class.java.getDeclaredField(buildProperty.key).get(null) as String
}
}
1 change: 1 addition & 0 deletions build-property/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
54 changes: 54 additions & 0 deletions build-property/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'kotlin-android'
id 'kotlin-kapt'
id 'kotlin-parcelize'
id 'dagger.hilt.android.plugin'
}

android {
namespace 'com.depromeet.threedays.buildproperty'
compileSdk 33

defaultConfig {
minSdk 26
targetSdk 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
alpha {
initWith debug
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
dataBinding true
}
}

dependencies {
implementation(jetpackDeps)
implementation(coroutines)

implementation deps.hilt.core
kapt deps.hilt.compiler

implementation deps.timber

testImplementation(testDeps)
androidTestImplementation(androidTestDeps)
}
Empty file.
21 changes: 21 additions & 0 deletions build-property/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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.depromeet.threedays.buildproperty

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.depromeet.threedays.buildproperty.test", appContext.packageName)
}
}
5 changes: 5 additions & 0 deletions build-property/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.depromeet.threedays.buildproperty">

</manifest>
Loading