Post

Unity Build 이슈 해결 모음 - Gradle build failed, type initializer exception

Unity Build 이슈 해결 모음 - Gradle build failed, type initializer exception

Hits


목차

1. gradle build failed 에러 관련

2. type initializer 에러 관련

3. 안드로이드 app bundle size 경고 관련


1. Gradle build failed 에러

  • 발생한 에러 목록들
1
2
3
4
5
6
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':launcher:checkReleaseDuplicateClasses'.


1
2
3
4
5
6
7
8
9
Starting a Gradle Daemon, 3 stopped Daemons could not be reused, use --status for details
WARNING:We recommend using a newer Android Gradle plugin to use compileSdk = 33

This Android Gradle plugin (7.1.2) was tested up to compileSdk = 32

This warning can be suppressed by adding
    android.suppressUnsupportedCompileSdk=33
to this project's gradle.properties


1
2
CommandInvokationFailure: Gradle build failed. 
/Applications/Unity/Hub/Editor/2022.3.4f1/PlaybackEngines/AndroidPlayer/OpenJDK/bin/java -classpath "/Applications/Unity/Hub/Editor/2022.3.4f1/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-7.2.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"


주요 현상

  • Android 빌드시 발생한 에러 였음.
  • Project Settings - Other Settigns 내부에 Minimum API Level 과 Target API Level 설정에 대한 이슈로 인해 발생한 빌드 에러였음.


해결 방법

  • Android 13.0 (API Level 33)부터 정책 강화로 인해 유저에게 Push 알림, 디스크 접근 권한 등을 승인 받도록 변경되었기 때문에 Assets/Plugins/Android/AndroidManifest.xml 파일에 권한 관련 코드를 추가해줘야함.

    지금은 또 level 34 로 변경됨.. 시간이 지날수록 최신화 확인 해야할듯

1
2
3
4
5
6
7
  <uses-permission android:name="android.permission.POST_NOTIFICATIONS" android:minSdkVersion="33"/>
          <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" android:minSdkVersion="33"/>
          <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" android:minSdkVersion="33"/>
          <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" android:minSdkVersion="33"/>
          <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32"/>
          <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32"/>
          android:requestLegacyExternalStorage="true"
  • 또한 Minimum API Level : 22
  • Target API Level : 33 으로 바꾸고 다시 빌드를 진행하면 해결됨.
  • Jenkins 빌드는 정상적으로 되고 수동 빌드 시 터지는 경우도 종종 발생하는데 이때 수동 빌드를 하고 싶다면..
  • Target API Level 을 auto 로 맞추고 빌드를 진행하면 수동 빌드는 해결된다.





2. Error: The type initializer for ‘Google.Protobuf.WellKnownTypes.StructReflection’ threw an exception.

주요 현상

  • mac mini 빌드 머신으로 빌드를 진행할 때 발생한 에러였다.


  • 20230822 추가 내용
  • iOS 빌드 자동화 후 빌드를 성공했음에도 불구하고 다음과 같은 에러가 발생핬다.
1
2
3
4
Exception: DescriptorValidationException: google.protobuf.Value.kind: Method ClearKind not found in Google.Protobuf.WellKnownTypes.Value 
Google.Protobuf.Reflection.OneofDescriptor.CreateAccessor (System.String clrName) (at <00000000000000000000000000000000>:0) Google.Protobuf.Reflection.OneofDescriptor..ctor 
(Google.Protobuf.Reflection.OneofDescriptorProto proto, Google.Protobuf.Reflection.FileDescriptor file, Google.Protobuf.Reflection.MessageDescriptor parent, System.Int32 index, System.String 
clrName) (at <00000000000000000000000000000000>:0) Google.Protobuf.Reflection.MessageDescriptor+<>c__DisplayClass5_0.<.ctor>b__0 (Google.Protobuf.Reflection.OneofDescriptorProto oneof, 
  • 에러 로그를 분석해보니 Refelction 어쩌고 저쩌고.. 확인해보니 link.xml 에 Google.Protobuf 를 preserve 해주는 코드가 빠져있었다.


원인

  • Unity 와 IL2CPP를 사용하여 C# reflection 과 열거형(enums)을 사용하는 중에 문제가 발생한 것으로 추측한다.
  • 코드가 reflection을 통해서만 접근되어 IL2CPP가 필요한 코드임을 인식하지 못해 삭제되었던거같다.


해결 방법

  • 프로젝트 내부의 Assets 폴더에 있는 link.xml 에 다음 내용을 추가.
1
2
3
<linker>
    <assembly fullname="Google.Protobuf" preserve="all"/>
</linker>


  • 만약 해결이 안된다면 다음을 추가.
1
<linker> <assembly fullname="DataModelBindings" preserve="all"/> </linker>





3. App Bundle Size Warning

Desktop View

주요 현상

  • 구글 플레이 스토어에 업로드 하기 위해서는 aab 파일로 빌드를 진행해야한다.
  • BuildSettings - Build App Bundle(Google Play) 항목을 체크하면 aab 파일로 빌드를 진행한다.
  • 하지만, 여기서 앱 빌드 용량이 150MB 이상일 경우 위 사진과 같은 경고가 발생한다.
  • 따라서 어드레서블 에셋 시스템을 통해 기본 앱 용량을 줄일 필요가 발생한다.
  • 초기 앱 기동에 필요한 리소스를 제외하고는 전부 어드레서블 그룹으로 묶어 에셋 번들로 패치 시스템을 통해 다운로드 받을 수 있게해야한다.
This post is licensed under CC BY 4.0 by the author.