Android12 SplashScreen 관련 에러 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

이지훈·2023년 1월 11일
0

다른 분들이 올려주신 SplashScreen API 적용법 블로그글과 공식 문서를 확인해서 적용해본 결과 api 31 이상에서는 SplashScreen 이 정상적으로 뜨는 것을 확인할 수 있었다

(Screen Api 적용 방법은 참고문서를 통해 대체하겠다. 다른 분들이 올리신 글들이 많기 때문에)

하지만 API 30이하의 기기에서는

java.lang.IllegalStateException:
You need to use a Theme.AppCompat theme (or descendant) with this activity.

해당 에러가 발생하는 이슈가 있었는데 installSplashScreeen() 함수의 위치를 액티비티의 super.onCreate() 윗쪽에 선언해두어도, Manifest 의 테마설정을 application이 아닌 activity에 적용해보라는 조언을 받고 적용해보았지만 마찬가지였다.

API 버전을 분기쳐서 30이하 에서는 다른 방식으로 Splash를 처리해줘야하나 검색을 해봤지만 SplashScreen 관련 대응방법은 검색해도 나오지 않아 애를 먹고 있었는데 이 방벙을 통해 해결하였다.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Base application theme. -->
    <style name="Theme.Sloth" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/sloth</item>
        <item name="colorPrimaryVariant">@color/primary_700</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor">@color/white</item>
        <!-- Customize your theme here. -->
        <item name="android:windowLightStatusBar">true</item>
    </style>
  
  <!--    기존 테마 파일 내부에 Splash 테마도 같이 선언, v31 버전의 새로운 themes.xml 파일에 선언 x-->

    <style name="Theme.Sloth.Splash" parent="Theme.SplashScreen">
        <item name="windowSplashScreenBackground">@color/white</item>
        <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_sloth_logo</item>
        <item name="windowSplashScreenAnimationDuration">1000</item>
        <item name="postSplashScreenTheme">@style/Theme.Sloth</item>
      
        <!-- Status bar and Nav bar configs -->
        <item name="android:statusBarColor">@color/white</item>
        <item name="android:navigationBarColor">@color/white</item>
        <item name="android:windowLightStatusBar">true</item>
    </style>

</resources>

나는 초기에 SplashScreen API를 적용할때 v31 values 패키지 내의 별도의 themes.xml 파일에 주석 기준 하단의 코드를 작성하였고. 따라서 다른 해결법이란 해결법을 다 적용해보아도 API 30 이하 버전의 기기에선 적용이 되지 않았던 것 같다.

혹시나 이와같이 같이 사소한 실수에 일주일이상 머리가 아플 사람이 더이상 나오지 않기를.. 희망하는 마음에 글을 작성해보았다.

PS. BaseActivity를 사용하는 경우 공식문서나 다른 medium 기술 블로그와 코드가 달라져 적용하는 방법이 헷갈릴 수 있는데 https://patrick-dev.tistory.com/36 해당 블로그의 글을 참고하면 BaseActivity를 사용하여도 적용시킬 수 있다.

참고 문서)
https://patrick-dev.tistory.com/36
https://sungbin.land/안드로이드12-스플래시-대응하기-1729f69dc33f
https://heegs.tistory.com/127
기타 안드로이드 공식 문서 및 안드로이드 공식 medium 블로그 참고

profile
실력은 고통의 총합이다. Android Developer

0개의 댓글