라벨이 Compose인 게시물 표시

Android Compose Ktor

이미지
사용 언어: Kotlin 1.9.22 사용 버전: Android Studio 2023.1.1 Patch 1 안드로이드 컴포즈 Ktor를 알아보겠습니다. Ktor는 Server와 통신하는 것을 도와주는 프레임워크입니다. 특이한 것은 Server와 Client 모두 사용 가능하다는 것입니다. Ktor는 JetBrain에서 공식적으로 지원하고 있으며 Kotlin으로 이루어졌습니다. Retrofit이 적용된 프로젝트에 Ktor로 변경하는 과정을 같이해봅시다. 참고 프로젝트: https://github.com/Jaehwa-Noh/Practice-Amphibians/tree/compose-ktor-amphibians-app App 용 Build.gradle에 dependencies를 추가해 줍니다. implementation("io.ktor:ktor-client-content-negotiation:2.3.7") implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.7") implementation("io.ktor:ktor-client-core:2.3.7") implementation("io.ktor:ktor-client-okhttp:2.3.7") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2") network 밑에 AmphibiansKtorApiService를 만듭니다. install에 ContentNegotiation을 적어줍니다. Text.Plain을 Json으로 변경할 것을 알려주고, ignoreUnknownKeys는 정의되지 않은 Key가 있으면 무시하겠다는 겁니다. defaultRequest는 기본 url 설정입니다. expectSuccess는 통신 성공을 예상한다는 뜻입니다. AmphibiansKtorApiService.kt Qualifie...

Android Compose Hilt with test

이미지
사용 언어: Kotlin 1.9.0 사용 버전: Android Studio Hedgehog 2023.1.1 Patch 1 안드로이드 컴포즈 Hilt with test를 알아보겠습니다. Hilt는 DI(Dependency Injection, 의존성 주입)를 편하게 하기 위한 라이브러리입니다. Dagger라는 DI 라이브러리를 Android에 사용하기 편하게 수정한 게 Hilt입니다. 이번 시간에는 Hilt를 사용하여 UI test, unit test를 하는 방법을 알아보겠습니다. 공식 사이트입니다. https://dagger.dev/hilt/ 참고 프로젝트: https://github.com/Jaehwa-Noh/Practice-Amphibians/tree/compose-hilt-amphibians-app Android Compose Hilt 게시글과 이어집니다. https://shwoghk14.blogspot.com/2024/01/android-compose-hilt.html test(테스트)를 위해서는 dependency(의존성) 설정이 필요합니다. 우리는 UI test와 unit test를 진행하기 때문에 이 부분을 app 용 build.gradle에 추가합니다. // For instrumentation tests androidTestImplementation("com.google.dagger:hilt-android-testing:2.50") kaptAndroidTest("com.google.dagger:hilt-compiler:2.50") // For local unit tests testImplementation("com.google.dagger:hilt-android-testing:2.50") kaptTest("com.google.dagger:hilt-compiler:2.50") Sync Now를 누릅니다. Unit test는 딱히 달라질 건 없습니다. 그대로 실행됩니다. Amphi...

Android Compose Hilt

이미지
사용 언어: Kotlin 1.9.0 사용 버전: Android Studio Hedgehog 2023.1.1 Patch 1 안드로이드 컴포즈 Hilt를 알아보겠습니다. Hilt는 DI(Dependency Injection, 의존성 주입)를 편하게 하기 위한 라이브러리입니다. Dagger라는 DI 라이브러리를 Android에 사용하기 편하게 수정한 게 Hilt입니다. 공식 사이트입니다. https://dagger.dev/hilt/ 참고 프로젝트: https://github.com/Jaehwa-Noh/Practice-Amphibians/tree/compose-hilt-amphibians-app 우선, 이러한 dependencies가 필요합니다. app 용 build.gradle에 현재 필요한 두 개만 적어줍니다. implementation("com.google.dagger:hilt-android:2.50") kapt("com.google.dagger:hilt-compiler:2.50") kapt를 인식하지 못하네요. Project 용 build.gradle로 갑니다. kotlin("kapt") version "1.9.0"을 적어줍니다. 그 후, app 용 build.gradle로 와서 kotlin("kapt")를 적어줍니다. 그리고 밑에 kapt를 적고 correctErrorTypes = true를 적어줍니다. Sync now를 눌러주세요. 간편하게 사용하기 위한 Hilt Gradle Plugin을 추가해 줍시다. project 용 build.gradle로 갑니다. id("com.google.dagger.hilt.android") version "2.50" apply false 추가해 줍니다. app 용 build.gralde로 갑니다. id("com.google.dagger.hilt.android") enableAggreg...