본문 바로가기
안드로이드

[안드로이드] nowinandroid 를 보면서 개인적으로 기억하고 싶은 것들

by keel_im 2022. 5. 29.
반응형

Google IO를 보면서 새로운 기술도 많이 나오고 정리할 것들도 많고, 이참에 프로젝트에도 최근 기술을 접목할겸 개인적으로 정리를 해볼까 합니다.

1. BuildSrc 하고 다른, 모듈을 통한 로직

보통은 프로젝트에서 BuildSrc를 적용을 하고 Dep이라는 파일로 라이브러리 버전을 체크하면서 활용하곤 했습니다. 하지만, 이번 nowinandroid 에서는 build-logic이라는 모듈을 활용해서 gradle 플러그인을 관리하는 것이 인상적이었다.

2. toml 을 통한 VersionCatalog

Gradle 7.4 에서는 기본으로 제공되는 것 같은 VersionCatalog 가 지원이 된다. Dep 을 넘어서 toml 으로 버전을 관리하는데, 생각보다 엄청 간단한 것 같아서 인상적이다.

[versions]
accompanist = "0.24.8-beta"
androidDesugarJdkLibs = "1.1.5"

[libraries]
accompanist-flowlayout = { group = "com.google.accompanist", name = "accompanist-flowlayout", version.ref = "accompanist" }
android-desugarJdkLibs = { group = "com.android.tools", name = "desugar_jdk_libs", version.ref = "androidDesugarJdkLibs" }

요런 느낌으로 버전이 관리되는데, 편리함을 느낄 수 는 있을 것 같다. 특별히 적응하는 것에 대한 코스트도 없을 것 같아서 적용을 해보고 싶은 부분이다.

3. 무엇보다 Compose

이제 공식 앱에서는 Compose를 무조건 사용하는 듯한 느낌이 든다. 생각보다 생산성도 뛰어난 것 같다. ViewSystem 이 익숙하지 않는 개발자들은 오히려 더 좋을지도, 하지만 ViewSystem 도 나쁘지 않고 현재 개발하고 있는 서비스들도 Compose 를 적용한다고는 하지만, 생각보다 많이 보수적으로 바라보지 않을까 한다. 하지만 그래도 구글에서 메인으로 미는 기술인 만큼 제대로 사용하고 싶은 마음은 든다.

  • UiState > 요런 개념도 같이 도입이 되는 흐름이다.
  • res 레이아웃 파일들은 전부 비어있다.

4. Benchmark 그리고 BaselineProfile

benchmark 모듈(?) baselineprofile 은 생각보다 인상적이었다. 무엇보다. 빠른 스타트를 해준다는 것이.. 요점은 프로젝트에서 제일 먼저 적용하고 싶은 부분이다. 일단 이론적으로는 이해는 했는데, 정확하게 아직은 설명은 힘든단계 인것 같다. 스스로가.

HSPLandroidx/compose/animation/AndroidFlingSpline$FlingResult;-><init>(FF)V
HSPLandroidx/compose/animation/AndroidFlingSpline;-><clinit>()V
HSPLandroidx/compose/animation/AndroidFlingSpline;-><init>()V
HSPLandroidx/compose/animation/AndroidFlingSpline;->flingPosition(F)Landroidx/compose/animation/AndroidFlingSpline$FlingResult;
HSPLandroidx/compose/animation/CrossfadeKt$$ExternalSyntheticOutline0;->m(Landroidx/compose/runtime/Composer;)V
HSPLandroidx/compose/animation/CrossfadeKt$Crossfade$1;-><init>(Ljava/lang/Object;Landroidx/compose/ui/Modifier;Landroidx/compose/animation/core/FiniteAnimationSpec;Lkotlin/jvm/functions/Function3;II)V

요런식으로 baseline-prof.txt 로 저장할 수 있다.

5. Hilt Dispatcher 주입

@Qualifier
@Retention(RUNTIME)
annotation class Dispatcher(val niaDispatcher: NiaDispatchers)

enum class NiaDispatchers {
    IO
}

@Provides
@Dispatcher(IO)
fun providesIODispatcher(): CoroutineDispatcher = Dispatchers.IO

디스패처를 주입을 받을 때, 위와 같이 선언을 해서 어노테이션으로 주입을 받는 점도 눈여겨 볼 부분이었다.

6. Proto 와 DataStore 사용

message UserPreferences {
reserved 2;
repeated int32 deprecated_int_followed_topic_ids = 1;
int32 topicChangeListVersion = 3;
int32 authorChangeListVersion = 4;
int32 episodeChangeListVersion = 5;
int32 newsResourceChangeListVersion = 6;
repeated int32 deprecated_int_followed_author_ids = 7;
bool has_done_int_to_string_id_migration = 8;
repeated string followed_topic_ids = 9;
repeated string followed_author_ids = 10;
}

```kotlin
fun providesUserPreferencesDataStore(
 userPreferencesSerializer: UserPreferencesSerializer,
 tmpFolder: TemporaryFolder
 ): DataStore<UserPreferences> =
 tmpFolder.testUserPreferencesDataStore(userPreferencesSerializer)

위 처럼 DataStore 와 protobuf 를 연결해서 사용하는 점은 기존에 몰랐었는데, 새로 알게되어서 신기한 부분이었다.

결론, 생각보다 빨리 발전한다.

너무나도 신기한 기술들이 많았습니다. 또한 Jetpack 도 유기적으로 라이브러리 마다 연결이 되어 있어서 단순히 ui를 만들고에서 조금 더 넘어서는 설계 능력이 필요할 것 같다. 그래서 더 재밌는 느낌도 있습니다. 여러분도 nowinandroid 프로젝트를 한번 보면서 공식 샘플을 한번 보시는 것을 추천드립니다.

 

https://github.com/android/nowinandroid

 

GitHub - android/nowinandroid: A fully functional Android app built entirely with Kotlin and Jetpack Compose

A fully functional Android app built entirely with Kotlin and Jetpack Compose - GitHub - android/nowinandroid: A fully functional Android app built entirely with Kotlin and Jetpack Compose

github.com

 

반응형

댓글