You need to use a theme.appcompat theme (or descendant) with this activity.

So I just created a new android project to play around with firebase tools (like firestore, functions, app distribution and whatnot), and I decided to reduce the pain of having to build the app and upload the app to Firebase App Distribution manually by automating release pipelines through Github Actions.

All was going good, then came a nightmare.

Although both the release and debug builds were working when built from Android studio, they were crashing on app launch, when built via github actions and downloaded via firebase app distribution, with this error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com....MyActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

I set out to find the fix for this issue, and wasted a lot of time searching for the fix, trying out many other alternatives, like adding AppCompat theme as parent directly.

What I missed was the root cause, and it was a pretty stupid reason, and as Lior Iluz suffered and finally pointed us in the right direction in this answer, I too, spent hours on such a trivial fix, The frustration of which I wouldn’t want on my worst enemy. So let me explain the solution.

Turns out, the Theme.MyProject name itself was the culprit behind all this, how so? Let’s see how the hierarchy of the themes work:

  • Theme.Light (not AppCompat)
  • Theme.Holo.Light (not AppCompat)
  • Platform.AppCompat.Light (Base for AppCompat)
  • Base.V7.Theme.AppCompat.Light
  • Base.Theme.AppCompat.Light
  • Theme.AppCompat.Light
  • Theme.AppCompat.Light.NoActionBar
  • Theme.AppCompat.DayNight.NoActionBar (Parent for my project’s theme)
  • Theme.MyProject (my project’s theme)

Above is the hierarchy of the themes, where the first theme is the root theme, and parent to the theme below.

So by this convention, If I define Theme.MyProject, it acts as a base theme (notice the Theme. prefix) and not as an AppCompat theme.

And If I rename Theme.MyProject to any other name, without any prefix, I’m good to go (like MyProjectTheme). This was the solution, the needle in the haystack.

One more thing I learned from this experience, is

ALWAYS find the root cause for an issue first!

I hope that if you were facing this issue, then you didn’t have to spend too much time for this fix.

And lastly, since I don’t have enough github reputations to comment, so here it is, special thanks to Lior Iluz for pointing me in the right direction before I lost my brains 😆

Also, readers, if you find that I misunderstood the hierarchy of the themes as mentioned above, please feel free to provide your feedback.

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

 위 메세지는 AlertDialog를 사용할 때 나타나며...

해결 방법은 2가지가 있다. 

첫번째는 import 를 다음과 같이 변경하는 것이다.

import android.support.v7.app.AlertDialog;  

-> import android.app.AlertDialog;

두번째는 

AndroidManifest에 다음 코드를 추가 하는 것

<activity
    android:name=".LoginActivity"
    android:theme="@style/Theme.AppCompat"
    >
</activity>

첫번째를 선택했을 경우, 

Unable to add window -- token null is not for an application

위에 같은 메세지가 나타날 수 있다. 

이 경우에는 아래와 같이 코딩이 되어 있을 것이다. 

AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());

이것을 다음과 같이 변경한다.
AlertDialog.Builder builder = new AlertDialog.Builder(WordListActivity.this);

AlertDialog.Builder builder = new  AlertDialog.Builder(this);

안드로이드 TabLayout 사용도중 Error Infalting 오류가 발생했습니다 ㅠㅠ

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

범인은.. Tablayout클래스의 내용문에 있었습니다.

android.support.v7.appcompat.R.styleable.textApperance ...

다른 방법으로는 AndroidManifest.xml에서
문제가 발생한 Activity를 아래와 같이 바뀌면 에러가 발생하지 않습니다.

<activity android:name=".RecommendFund" android:theme="@style/Theme.AppCompat" > </activity>

저작자표시

'모바일 > Android_Java' 카테고리의 다른 글

[android] theme, attr, style, color ,values 정리  (0) 2021.02.26
TabLayout Custom View View 안에있는 TextView Selected 안될때 해결법!  (0) 2021.02.25
[안드로이드] You need to use a Theme.AppCompat theme (or descendant) with this activity  (0) 2021.02.25
CollapsingTollbar 스크롤 하면서 아이콘 위치 변경하기  (0) 2021.01.12
[카카오페이 메인 클론코딩 2] onslide , onStateChanged, setalpha(블러처리/ 흐리게 하면서 사라지게함), scaleX(화면이 커지고 작아지고)구현  (0) 2021.01.10
[카카오페이 메인 클론코딩 1] BottomSheetBehavior 구현  (0) 2021.01.10

What is AppCompat theme?

The AppCompat support library provides themes to build apps with the Material Design specification. A theme with a parent of Theme. AppCompat is also required for an Activity to extend AppCompatActivity . The first step is to customize your theme's color palette to automatically colorize your app.

What is AppCompat activity?

↳ androidx.appcompat.app.AppCompatActivity. Base class for activities that wish to use some of the newer platform features on older Android devices. Some of these backported features include: Using the action bar, including action items, navigation modes and more with the setSupportActionBar(Toolbar) API.