From c6ff7a3eaf7c3a0554957f2abcfbd4a76de2ff82 Mon Sep 17 00:00:00 2001 From: s9hn Date: Tue, 29 Apr 2025 17:48:58 +0900 Subject: [PATCH 1/2] =?UTF-8?q?build:=20core:network=20=EB=AA=A8=EB=93=88?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/network/.gitignore | 1 + core/network/build.gradle.kts | 20 ++++++++++++++++++++ core/network/consumer-rules.pro | 0 core/network/proguard-rules.pro | 21 +++++++++++++++++++++ core/network/src/main/AndroidManifest.xml | 4 ++++ settings.gradle.kts | 1 + 6 files changed, 47 insertions(+) create mode 100644 core/network/.gitignore create mode 100644 core/network/build.gradle.kts create mode 100644 core/network/consumer-rules.pro create mode 100644 core/network/proguard-rules.pro create mode 100644 core/network/src/main/AndroidManifest.xml diff --git a/core/network/.gitignore b/core/network/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/core/network/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core/network/build.gradle.kts b/core/network/build.gradle.kts new file mode 100644 index 000000000..11e0f0c02 --- /dev/null +++ b/core/network/build.gradle.kts @@ -0,0 +1,20 @@ +import com.into.websoso.setNamespace + +plugins { + id("websoso.android.library") +} + +android { + setNamespace("core.network") + buildFeatures { + buildConfig = true + } +} + +dependencies { + implementation(libs.retrofit) + implementation(libs.retrofit.kotlinx.serialization) + implementation(libs.serialization.json) + implementation(libs.okhttp) + implementation(libs.okhttp.logging.interceptor) +} diff --git a/core/network/consumer-rules.pro b/core/network/consumer-rules.pro new file mode 100644 index 000000000..e69de29bb diff --git a/core/network/proguard-rules.pro b/core/network/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/core/network/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/core/network/src/main/AndroidManifest.xml b/core/network/src/main/AndroidManifest.xml new file mode 100644 index 000000000..8bdb7e14b --- /dev/null +++ b/core/network/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + diff --git a/settings.gradle.kts b/settings.gradle.kts index 3a8bc6092..df89285c5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,4 +23,5 @@ include(":app") include( ":core:resource", ":core:designsystem", + ":core:network", ) From 0b6a382b49264d9f5500d9ad2073e7f105635bcb Mon Sep 17 00:00:00 2001 From: s9hn Date: Tue, 29 Apr 2025 18:16:13 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EB=A0=88=ED=8A=B8=EB=A1=9C?= =?UTF-8?q?=ED=95=8F=20=EB=84=A4=ED=8A=B8=EC=9B=8C=ED=81=AC=20=EB=9D=BC?= =?UTF-8?q?=EC=9D=B4=EB=B8=8C=EB=9F=AC=EB=A6=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 1 + core/network/build.gradle.kts | 14 ++++++ .../websoso/core/network/di/NetworkModule.kt | 49 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 core/network/src/main/java/com/into/websoso/core/network/di/NetworkModule.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5e330fc93..6e517c7ad 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -84,6 +84,7 @@ dependencies { // 프로젝트 의존성 implementation(projects.core.resource) implementation(projects.core.designsystem) + implementation(projects.core.network) // AndroidX 및 Jetpack 기본 라이브러리 implementation(libs.androidx.core.ktx) diff --git a/core/network/build.gradle.kts b/core/network/build.gradle.kts index 11e0f0c02..7c5558492 100644 --- a/core/network/build.gradle.kts +++ b/core/network/build.gradle.kts @@ -1,3 +1,4 @@ +import com.into.websoso.buildConfigs import com.into.websoso.setNamespace plugins { @@ -6,6 +7,19 @@ plugins { android { setNamespace("core.network") + buildTypes { + debug { + buildConfigs(rootDir) { + string(name = "BASE_URL", key = "debug.base.url") + } + } + + release { + buildConfigs(rootDir) { + string(name = "BASE_URL", key = "release.base.url") + } + } + } buildFeatures { buildConfig = true } diff --git a/core/network/src/main/java/com/into/websoso/core/network/di/NetworkModule.kt b/core/network/src/main/java/com/into/websoso/core/network/di/NetworkModule.kt new file mode 100644 index 000000000..e499653db --- /dev/null +++ b/core/network/src/main/java/com/into/websoso/core/network/di/NetworkModule.kt @@ -0,0 +1,49 @@ +package com.into.websoso.core.network.di + +import com.into.websoso.core.network.BuildConfig +import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import kotlinx.serialization.json.Json +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Retrofit +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object NetworkModule { + private const val BASE_URL = BuildConfig.BASE_URL + private const val CONTENT_TYPE = "application/json" + + @Provides + @Singleton + fun provideRetrofit( + json: Json, + client: OkHttpClient, + ): Retrofit = + Retrofit + .Builder() + .baseUrl(BASE_URL) + .client(client) + .addConverterFactory(json.asConverterFactory(CONTENT_TYPE.toMediaType())) + .build() + + @Provides + @Singleton + internal fun provideJson(): Json = Json { ignoreUnknownKeys = true } + + @Provides + @Singleton + internal fun provideOkHttpClient(): OkHttpClient = + OkHttpClient + .Builder() + .addInterceptor( + HttpLoggingInterceptor().apply { + if (BuildConfig.DEBUG) setLevel(HttpLoggingInterceptor.Level.BODY) + }, + ).build() +}