AGP 8.0 업데이트 과정, 고난, 해결

David·2023년 11월 17일
0

🥺 AGP 8.0이 사용하고 싶어요


현재 회사에서 레거시를 걷어내고 컴포즈로 바꾸는 작업을
맡아서 하고 있는데
그마 스펙에 맞게 개발을 할려고 보면
최신 컴포즈를 반영해서 작업해야 안정적인 경우가 많습니다.

가령 이번년도 상반기 세미나에서 컴포즈가
현재 BottomSheet에서 키보드가 나타날 시
가려진다는 이슈가 있었습니다.

이를 최신 버전에서 fix된 부분을 확인하다보니
프로젝트를 들어갈 때 컴포즈의 버전을
최신화 할려고 노력 합니다.

근데 1.2.0-alpha08 버전을 사용하려면
AGP 8.0 이상을 사용하라고 안내가 나왔습니다. 😱

그래서 Gradle Version 을 7.4.0 ➡️ 8.1.0 으로 업데이트 하는 과정을 시작했습니다 🏃🏼🏃🏼🏃🏼

📌 Gradle 설정


  • app(module)/build.gradle 설정
  • build.gradle 설정

  • gradle.properties 설정

  • gradle/wrapper/gradle-wrapper.properties 설정

    • gradlew 8.0 으로 업데이트

대략적인 셋팅은 모두 끝났다.
개발 시 문제 없어서 다 끝난 줄 알았다 💭


💦 심사 당일 PlayConsole 업로드가 안 된다


🚨 난생 처음 보는 메세지가 나왔다

Android App Bundle에 용량이 너무 큰 Proguard 가독화 파일(2492MB)이 포함되어 있습니다.
허용되는 최대 크기는 1600MB입니다.


🔎 까보자, 찾아보자


AAB를 어떻게 까볼까 ❓


우선 까보기(?)에 앞서 궁금증이 먼저 생겼다.

Q. AAB 파일은 어떤 파일일까?!
A. file 명령어를 이용해보자



결과는 Zip 파일이다
=> 그러면 unzip 하면 풀린다!!

👁️ unzip한 .aab를 들여다보자

GrandPerspective 를 이용하여 파일을 보면 proguard.map 이 2.44GB 차지한다 😱

뭐가 들어있길래 도대체 2.44GB란 말인가...
vi 로 들여다보면...

androidx.compose.material.icons.Icons$(아이콘이름) 에
PathBuilder라는 타입의 클래스 정의가 엄청나게 많이 들어가 있었다.

⌨️ 인피니트 구글링

위의 파일을 바탕으로 구글링, 스택오버플로우 검색해봤으나 나오질 않는다 😢

⭐️ 그러다 Google IssueTrcker에서 완벽하게 동일한 이슈를 찾을 수 있었다.

위 이슈글에서 마지막에
AGP를 최신 8.2로 올리면 해결된다라고 적혀있고
status: Fixed로 되어있었다.

드디어... 빛이 보인다 ✨


😵‍💫 스튜디오와 AGP를 업데이트하다.


💁🏻 build.gradle

  • gradleVersion = '8.2.0-rc02

💁🏻 gradle/wrapper/gradle-wrapper.properties 파일

  • distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip

💁🏻 안드로이드 Hedgehog 프리뷰 다운로드


🤩 Hedgehog 에서 사인 빌드 후 bundle 파일의 proguard.map

정말 크기가 줄었다 !!!!!!!!

여기까지가 빌드의 험난한 과정이였다.
하지만 여기가 끝이 아니다.

AGP 8.0 이상이 되면서
다른 라이브러리들도 추가 설정이 필요했다.


🔠 proguard 및 parcelable Extra api 변경 사항


🔓 Gson Proguard 설정

##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken

##---------------End: proguard configuration for Gson  ----------

🔓 Retrofit Proguard 설정

# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod

# Retrofit does reflection on method and parameter annotations.
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations

# Keep annotation default values (e.g., retrofit2.http.Field.encoded).
-keepattributes AnnotationDefault

# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}

# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**

# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit

# Top-level functions that can only be used by Kotlin.
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*

# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>

# Keep inherited services.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface * extends <1>

# With R8 full mode generic signatures are stripped for classes that are not
# kept. Suspend functions are wrapped in continuations where the type argument
# is used.
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation

# R8 full mode strips generic signatures from return types if not kept.
-if interface * { @retrofit2.http.* public *** *(...); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>

# With R8 full mode generic signatures are stripped for classes that are not kept.
-keep,allowobfuscation,allowshrinking class retrofit2.Response

🔓 Kakao Proguard 설정

# Kakao
-keep class com.kakao.sdk.**.model.* { *; }
-keep class * extends com.google.gson.TypeAdapter
## R8 추가된 부분
-keep interface com.kakao.sdk.**.*Api

🚨 Parcelable 처리

기존에 Intent에 전달하는 parcelable 직렬화 데이터를 버전에 따라 분기 처리하였는데
해당 API가 업로드하면서 작동하지 않아
최신 core ktx 라이브러리에 제공되는 Compat API를 사용하여 핫픽스 후 해결했다.

Before code

inline fun <reified T : Parcelable> Intent.getParcelableSafetyExtra(key: String): T? =
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
        getParcelableExtra(
            key,
            T::class.java
        )
    } else {
        @Suppress("DEPRECATION")
        getParcelableExtra(key) as? T
    }

After code

inline fun <reified T : Parcelable> Intent.getParcelableSafetyExtra(key: String): T? =
	IntentCompat.getParcelableExtra(this, key, T::class.java)

👏🏻 마치며

최신 컴포즈를 사용할려고
AGP를 호기롭게 올리며
시작한 스노우볼이 참 많이 굴러왔다.

덕분에 심사 당일 야근도하고
핫픽스도 하며 정신없었지만

어려운 환경속에 나를 던지면서
나는 또 성장하였고
멘탈이 강해졌으며

좋은 동료로 하여금 너무 큰 도움과
힘이 되어 평소에 전하지 못한
감사함도 전했다 (To. Young)

동일하거나 비슷한 문제에 직면한
개발자분께서 이 글을 읽고
어둠속을 헤처나가길 바라며
본 포스트는 마치겠습니다 🙇🏻‍♂️

profile
공부하는 개발자

0개의 댓글

관련 채용 정보