flutter_naver_login icon indicating copy to clipboard operation
flutter_naver_login copied to clipboard

Android에서 갑자기 다음 에러가 뜹니다: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

Open gracegyu opened this issue 2 years ago • 13 comments

Flutter v2.10에서 naver login을 접목하고 있습니다. Android에서 로그인이 잘되었는데, 아래코드 호출하면 갑자기 다음의 에러가 뜹니다. Real device에서는 잘되고, Emulator에서만 이 에러가 뜹니다.

NaverLoginResult res = await FlutterNaverLogin.logIn();

I/NaverIdLogin|com.mycompay.myapp|OAuthLoginEncryptedPreferenceManager(21114): access token is expired. E/MethodChannel#flutter_naver_login(21114): Failed to handle method call E/MethodChannel#flutter_naver_login(21114): java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. E/MethodChannel#flutter_naver_login(21114): at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:852) E/MethodChannel#flutter_naver_login(21114): at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:815) E/MethodChannel#flutter_naver_login(21114): at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:703) E/MethodChannel#flutter_naver_login(21114): at androidx.appcompat.app.AppCompatDialog.setContentView(AppCompatDialog.java:95) E/MethodChannel#flutter_naver_login(21114): at com.navercorp.nid.progress.NidProgressDialog.init(NidProgressDialog.kt:39) E/MethodChannel#flutter_naver_login(21114): at com.navercorp.nid.progress.NidProgressDialog.(NidProgressDialog.kt:32) E/MethodChannel#flutter_naver_login(21114): at com.navercorp.nid.oauth.NidOAuthLogin.refreshToken(NidOAuthLogin.kt:196) E/MethodChannel#flutter_naver_login(21114): at com.navercorp.nid.NaverIdLoginSDK.authenticate(NaverIdLoginSDK.kt:104) E/MethodChannel#flutter_naver_login(21114): at com.yoonjaepark.flutter_naver_login.FlutterNaverLoginPlugin.login(FlutterNaverLoginPlugin.kt:193) E/MethodChannel#flutter_naver_login(21114): at com.yoonjaepark.flutter_naver_login.FlutterNaverLoginPlugin.onMethodCall(FlutterNaverLoginPlugin.kt:127) E/MethodChannel#flutter_naver_login(21114): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) E/MethodChannel#flutter_naver_login(21114): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296) E/MethodChannel#flutter_naver_login(21114): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320) E/MethodChannel#flutter_naver_login(21114): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12) E/MethodChannel#flutter_naver_login(21114): at android.os.Handler.handleCallback(Handler.java:938) E/MethodChannel#flutter_naver_login(21114): at android.os.Handler.dispatchMessage(Handler.java:99) E/MethodChannel#flutter_naver_login(21114): at android.os.Looper.loopOnce(Looper.java:201) E/MethodChannel#flutter_naver_login(21114): at android.os.Looper.loop(Looper.java:288) E/MethodChannel#flutter_naver_login(21114): at android.app.ActivityThread.main(ActivityThread.java:7839) E/MethodChannel#flutter_naver_login(21114): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#flutter_naver_login(21114): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) E/MethodChannel#flutter_naver_login(21114): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) I/flutter (21114): error on Naver login: PlatformException(error, You need to use a Theme.AppCompat theme (or descendant) with this activity., null, java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. I/flutter (21114): at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:852) I/flutter (21114): at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:815) I/flutter (21114): at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:703) I/flutter (21114): at androidx.appcompat.app.AppCompatDialog.setContentView(AppCompatDialog.java:95) I/flutter (21114): at com.navercorp.nid.progress.NidProgressDialog.init(NidProgressDialog.kt:39) I/flutter (21114): at com.navercorp.nid.progress.NidProgressDialog.(NidProgressDialog.kt:32) I/flutter (21114): at com.navercorp.nid.oauth.NidOAuthLogin.refreshToken(NidOAuthLogin.kt:196) I/flutter (21114): at com.navercorp.nid.NaverIdLoginSDK.authenticate(NaverIdLoginSDK.kt:104) I/flutter (21114): at com.yoonjaepark.flutter_naver_login.FlutterNaverLoginPlugin.login(FlutterNaverLoginPlugin.kt:193) I/flutter (21114): at com.yoonjaepark.flutter_naver_login.FlutterNaverLoginPlugin.onMethodCall(FlutterNaverLoginPlugin.kt:127) I/flutter (21114): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) I/flutter (21114): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296) I/flutter (21114): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320) I/flutter (21114): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12) I/flutter (21114): at android.os.Handler.handleCallback(Handler.java:938) I/flutter (21114): at android.os.Handler.dispatchMessage(Handler.java:99) I/flutter (21114): at android.os.Looper.loopOnce(Looper.java:201) I/flutter (21114): at android.os.Looper.loop(Looper.java:288) I/flutter (21114): at android.app.ActivityThread.main(ActivityThread.java:7839) I/flutter (21114): at java.lang.reflect.Method.invoke(Native Method) I/flutter (21114): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) I/flutter (21114): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) I/flutter (21114): )

gracegyu avatar Feb 28 '22 04:02 gracegyu

이번 naver login 5.0.1 업데이트 이후로 네이버에서 dialog 등을 AppCompat Theme 로 모두 변경하면서 생기는 문제입니다.

android/app/src/main/AndroidManifest.xml 에

...

 <activity android:name="com.navercorp.nid.oauth.activity.NidOAuthWebViewActivity"
                  android:theme="@style/LaunchTheme">

코드를 추가하신뒤

android/app/src/main/res/values/styles.xml 에

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             Flutter draws its first frame -->
        <item name="android:windowBackground">@drawable/launch_background</item>
    </style>
</resources>

코드를

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             Flutter draws its first frame -->
        <item name="android:windowBackground">@drawable/launch_background</item>
    </style>
</resources>

로 변경하여주시면됩니다. (@android:style/Theme.Black.NoTitleBar -> Theme.AppCompat.DayNight.NoActionBar)

관련 코드는 #57 에서 확인 가능하시며 수정내용을 반영해주시기 바랍니다.

감사합니다.

syonkr avatar Mar 02 '22 07:03 syonkr

Theme.AppCompat.DayNight.NoActionBar로 설정하면 아래 에러가 납니다. Theme.AppCompat.Night.NoActionBar로 설정하니 빌드/실행이 되네요. 감사합니다.

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:processDebugResources'.

A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction Android resource linking failed ERROR:AAPT: error: resource style/Theme.AppCompat.DayLight.NoActionBar (aka com.vatech.cleverpam:style/Theme.AppCompat.DayLight.NoActionBar) not found. error: failed linking references.

gracegyu avatar Mar 02 '22 08:03 gracegyu

@gracegyu 오류 로그상으로 DayNight가 아닌 DayLight로 쓰신거같긴하지만 ...우선 AppCompat 을 사용하는게 주목적이라 따로 디자인에 문제가 없으시다면 그대로 사용하셔도 될거같습니다. ☺️

감사합니다.

syonkr avatar Mar 02 '22 08:03 syonkr

오타을 입력했군요. 확인했습니다. 대단히 감사합니다.

gracegyu avatar Mar 02 '22 08:03 gracegyu

Flutter 2.10.3 사용중입니다!

android>app>src>main>androidmanifest.xml 추가했고

android>app>src>main>res>values>styles.xml

Woojin-Crive avatar Mar 07 '22 09:03 Woojin-Crive

@Woojin-Crive 올려주신 내용을 읽기는 힘들지만 동일한 오류로 추정됩니다. android/app/src/main/AndroidManifest.xml 에 있는 MainActivity 의 theme가 "@style/LaunchTheme"로 되어있는지 확인부탁드립니다.

syonkr avatar Mar 08 '22 02:03 syonkr

이하는 android/app/src/main/AndroidManifest.xml 입니다.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.app.myapp">

    <queries>
        <!-- If your app opens https URLs -->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="https" />
        </intent>

    </queries>

   <application
       android:label="app"
       android:requestLegacyExternalStorage="true"
       android:exported="true"
       android:icon="@mipmap/ic_launcher">
       <meta-data
           android:name="com.naver.sdk.clientId"
           android:value="@string/client_id" />
       <meta-data
           android:name="com.naver.sdk.clientSecret"
           android:value="@string/client_secret" />
       <meta-data
           android:name="com.naver.sdk.clientName"
           android:value="@string/client_name" />
       <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:exported="true"
            android:theme="@style/Theme.AppCompat"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <activity
            android:name="com.navercorp.nid.oauth.NidOAuthBridgeActivity"
            android:exported="true" 
            tools:replace="android:theme"
            android:theme="@style/Theme.AppCompat"/>

        <activity
            android:name="com.navercorp.nid.oauth.activity.NidOAuthWebViewActivity"
            android:exported="true" 
            tools:replace="android:theme"
            android:theme="@style/Theme.AppCompat"/>

        <activity
            android:name="com.navercorp.nid.oauth.activity.NidOAuthCustomTabActivity"
            android:exported="true"
            tools:replace="android:theme"
            android:theme="@style/Theme.AppCompat"/>

        <activity 
          android:name="com.nhn.android.naverlogin.ui.OAuthCustomTabActivity"
          android:exported="true" 
          android:theme="@style/Theme.AppCompat"/>

       <meta-data
           android:name="flutterEmbedding"
           android:value="2" />
   </application>
</manifest>

그냥 Theme.AppCompat으로 하니까 잘 되네요.. !

Woojin-Crive avatar Mar 08 '22 03:03 Woojin-Crive

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDevDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed
     AAPT: error: resource android:style[/Theme.AppCompat.DayNight.NoActionBar]() not found.
     error: failed linking references.

FYI) 해당 코멘트를 보고 작업할 때 위와같은 오류 혹은 다른 오류가 발생한다면 아래 방법으로 시도해보세요!

  1. com.nhn.android.naverlogin.ui.OAuthCustomTabActivity 의 theme을 @style/Theme.AppCompat으로 설정
  2. com.navercorp.nid.oauth.activity.NidOAuthWebViewActivity 의 theme을 @style/Theme.AppCompat으로 설정
  3. .MainActivity 의 theme을 @style/Theme.AppCompat으로 설정

소스 코드

AndroidManifest.xml
...

<application
    android:label="@string/app_name"
    ...>

    <activity 
            android:name="com.nhn.android.naverlogin.ui.OAuthCustomTabActivity"
            android:exported="true" 
            android:theme="@style/Theme.AppCompat" />

    <activity 
            android:name="com.navercorp.nid.oauth.activity.NidOAuthWebViewActivity"
            android:theme="@style/Theme.AppCompat" />

    ...

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

혹시나 위 소스코드에 문제가 있으면 코멘트 등록해주세요! : )

Bigstar1108 avatar Mar 22 '22 09:03 Bigstar1108

해당 코멘트를 보고 작업했는데, 안드로이드 버전 12에서만 해결되지 않아서 MainActivity의 theme을 @style/Theme.AppCompat로 설정해 해결했습니다.

Heewookji avatar Apr 07 '22 02:04 Heewookji

MainActivity의 theme을 @style/Theme.AppCompat로 바꾸면 스플래쉬를 적용못시키는데 해결책이 나오지 않았나요??

보내주신 코드로 values를 수정해도 같은에러가 발생합니다.

안드로이드12인 values-v31의 경우

parent="@style/Theme.AppCompat.DayNight.NoActionBar" 를 넣으면 작동됩니다

11버전 이하에서는 작동하지 않습니다.

liemeon avatar Jul 14 '22 07:07 liemeon

모든버전 통틀어서 로그아웃 기능이 들어있는지 확인바랍니다. 로그아웃이 없을경우 11이하버전에서는 해당 에러가 발생합니다.

liemeon avatar Jul 15 '22 09:07 liemeon

LaunchTheme 내용을 수정하거나 MainActivity에 AppCompat을 적용하면 스플래시 화면에 원치 않는 변경이 생길 수 있어서 LaunchTheme 수정하지 말고, 또한 MainActivity에도 기존 LaunchTheme 그대로 적용하는게 어떨까 싶습니다.

즉, 원래 상태에서 AndroidManifest.xml에 아래 코드만 추가하는 임시 방편을 제안합니다. 그리고 패키지의 AndroidManifest에 추가한다면 모든 사람이 각자의 프로젝트에 넣을 필요 없이 잘 동작할 것 같습니다 (확인 필요)

<activity android:name="com.navercorp.nid.oauth.activity.NidOAuthWebViewActivity"
    android:theme="@style/Theme.AppCompat"
    android:exported="true"
    />

wph144 avatar Sep 06 '22 14:09 wph144

이 코드 추가하면 <activity android:name="com.navercorp.nid.oauth.activity.NidOAuthWebViewActivity" android:theme="@style/LaunchTheme"/>

이런 오류가 뜨네요.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : Attribute activity#com.navercorp.nid.oauth.activity.NidOAuthWebViewActivity@theme value=(@style/LaunchTheme) from AndroidManifest.xml:70:13-47
  	is also present at [com.navercorp.nid:oauth:5.2.0] AndroidManifest.xml:41:13-75 value=(@style/Theme.AppCompat.Transparent.NoActionBar).
  	Suggestion: add 'tools:replace="android:theme"' to <activity> element at AndroidManifest.xml:69:9-70:49 to override.

이렇게 . MainActivity 를 수정하면 에러 없고요.

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

byungjuJin avatar Jan 12 '23 06:01 byungjuJin