diff --git a/.github/workflows/pr_checker.yml b/.github/workflows/pr_checker.yml index 7e17350e..4d0ca6f3 100644 --- a/.github/workflows/pr_checker.yml +++ b/.github/workflows/pr_checker.yml @@ -38,6 +38,12 @@ jobs: - name: Create Local Properties run: touch local.properties + - name: Access Local Properties + env: + base_url: ${{ secrets.BASE_URL }} + run: | + echo base.url=\"$base_url\" >> local.properties + - name: Build debug APK run: ./gradlew assembleDebug --stacktrace diff --git a/app/src/main/java/com/teumteum/teumteum/di/RetrofitModule.kt b/app/src/main/java/com/teumteum/teumteum/di/RetrofitModule.kt index 61a9160f..6c6d7927 100644 --- a/app/src/main/java/com/teumteum/teumteum/di/RetrofitModule.kt +++ b/app/src/main/java/com/teumteum/teumteum/di/RetrofitModule.kt @@ -1,56 +1,59 @@ package com.teumteum.teumteum.di import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory +import com.teumteum.teumteum.BuildConfig.BASE_URL import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import kotlinx.coroutines.InternalCoroutinesApi -import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json +import okhttp3.Interceptor import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Converter import retrofit2.Retrofit -import javax.inject.Qualifier import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) object RetrofitModule { - @Qualifier - @Retention(AnnotationRetention.BINARY) - annotation class TeumTeum - - @Provides - @Singleton - fun provideOkHttpClient( - logger: HttpLoggingInterceptor - ): OkHttpClient = OkHttpClient.Builder().addInterceptor(logger) - .build() + private const val APPLICATION_JSON = "application/json" @Provides @Singleton - fun provideLogger(): HttpLoggingInterceptor = HttpLoggingInterceptor().apply { + fun provideHttpLoggingInterceptor(): Interceptor = HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.BODY } - @OptIn(ExperimentalSerializationApi::class, InternalCoroutinesApi::class) @Provides @Singleton - @TeumTeum - fun provideTeumTeumRetrofit(json: Json, client: OkHttpClient): Retrofit { - kotlinx.coroutines.internal.synchronized(this) { - val retrofit = Retrofit.Builder().baseUrl("").client(client) - .addConverterFactory(json.asConverterFactory("application/json".toMediaType())) - .build() - return retrofit ?: throw RuntimeException("Retrofit creation failed.") - } + fun provideJson(): Json = Json { + ignoreUnknownKeys = true + prettyPrint = true } @Provides @Singleton - fun provideJson(): Json = Json { - ignoreUnknownKeys = true - } + fun provideOkHttpClient( + loggingInterceptor: Interceptor + ): OkHttpClient = OkHttpClient.Builder() + .addInterceptor(loggingInterceptor) + .build() + + @Provides + @Singleton + fun provideJsonConverter(json: Json): Converter.Factory = + json.asConverterFactory(APPLICATION_JSON.toMediaType()) + + @Provides + @Singleton + fun provideTeumTeumRetrofit( + client: OkHttpClient, + factory: Converter.Factory + ): Retrofit = Retrofit.Builder() + .baseUrl(BASE_URL) + .client(client) + .addConverterFactory(factory) + .build() } \ No newline at end of file diff --git a/app/src/main/java/com/teumteum/teumteum/di/ServiceModule.kt b/app/src/main/java/com/teumteum/teumteum/di/ServiceModule.kt index e7bde678..4b901945 100644 --- a/app/src/main/java/com/teumteum/teumteum/di/ServiceModule.kt +++ b/app/src/main/java/com/teumteum/teumteum/di/ServiceModule.kt @@ -14,6 +14,6 @@ import javax.inject.Singleton object ServiceModule { @Singleton @Provides - fun provideSampleService(@RetrofitModule.TeumTeum teumteumRetrofit: Retrofit) = + fun provideSampleService(teumteumRetrofit: Retrofit) = teumteumRetrofit.create(SampleService::class.java) } \ No newline at end of file diff --git a/build-logic/convention/src/main/java/com/teumteum/convention/src/main/kotlin/plugins/AndroidApplicationPlugin.kt b/build-logic/convention/src/main/java/com/teumteum/convention/src/main/kotlin/plugins/AndroidApplicationPlugin.kt index df69dc42..a398c252 100644 --- a/build-logic/convention/src/main/java/com/teumteum/convention/src/main/kotlin/plugins/AndroidApplicationPlugin.kt +++ b/build-logic/convention/src/main/java/com/teumteum/convention/src/main/kotlin/plugins/AndroidApplicationPlugin.kt @@ -2,6 +2,7 @@ package plugins import Constants import com.android.build.api.dsl.ApplicationExtension +import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties import com.teumteum.convention.src.main.kotlin.ext.androidTestImplementation import com.teumteum.convention.src.main.kotlin.ext.getBundle import com.teumteum.convention.src.main.kotlin.ext.getLibrary @@ -49,49 +50,19 @@ class AndroidApplicationPlugin : Plugin { buildTypes { debug { -// buildConfigField( -// "String", -// "BASE_URL", -// gradleLocalProperties(rootDir).getProperty("test.base.url"), -// ) -// -// buildConfigField( -// "String", -// "NATIVE_APP_KEY", -// gradleLocalProperties(rootDir).getProperty("test.native.app.key"), -// ) -// -// buildConfigField( -// "String", -// "AMPLITUDE_API_KEY", -// gradleLocalProperties(rootDir).getProperty("amplitude.api.test.key"), -// ) -// -// manifestPlaceholders["NATIVE_APP_KEY"] = -// gradleLocalProperties(rootDir).getProperty("testNativeAppKey") -// } -// -// release { -// buildConfigField( -// "String", -// "BASE_URL", -// gradleLocalProperties(rootDir).getProperty("base.url"), -// ) -// -// buildConfigField( -// "String", -// "NATIVE_APP_KEY", -// gradleLocalProperties(rootDir).getProperty("native.app.key"), -// ) -// -// buildConfigField( -// "String", -// "AMPLITUDE_API_KEY", -// gradleLocalProperties(rootDir).getProperty("amplitude.api.key"), -// ) -// -// manifestPlaceholders["NATIVE_APP_KEY"] = -// gradleLocalProperties(rootDir).getProperty("nativeAppKey") + buildConfigField( + "String", + "BASE_URL", + gradleLocalProperties(rootDir).getProperty("base.url"), + ) + } + + release { + buildConfigField( + "String", + "BASE_URL", + gradleLocalProperties(rootDir).getProperty("base.url"), + ) isMinifyEnabled = false proguardFiles( diff --git a/core/data/build.gradle.kts b/core/data/build.gradle.kts index 59193926..f38c1bc8 100644 --- a/core/data/build.gradle.kts +++ b/core/data/build.gradle.kts @@ -8,19 +8,19 @@ plugins { android { buildTypes { debug { -// buildConfigField( -// "String", -// "BASE_URL", -// gradleLocalProperties(rootDir).getProperty("test.base.url"), -// ) + buildConfigField( + "String", + "BASE_URL", + gradleLocalProperties(rootDir).getProperty("base.url"), + ) } release { -// buildConfigField( -// "String", -// "BASE_URL", -// gradleLocalProperties(rootDir).getProperty("base.url"), -// ) + buildConfigField( + "String", + "BASE_URL", + gradleLocalProperties(rootDir).getProperty("base.url"), + ) } }