IT TIP

전면 광고 AdMob 광고 : 'IllegalStateException : 전체 화면 활동 만 방향을 요청할 수 있습니다.'

itqueen 2020. 11. 1. 19:04
반응형

전면 광고 AdMob 광고 : 'IllegalStateException : 전체 화면 활동 만 방향을 요청할 수 있습니다.'


배경

전면 광고 (전체 화면 광고)를 표시하기 위해 Admob SDK가 사용 된 앱이 있습니다.

최근 Google은 admob (firebase 광고)를 포함하여 다른 많은 것 (빌드 도구, gradle 플러그인, IDE 등)과 함께 SDK를 업데이트했습니다.

compile 'com.google.firebase:firebase-ads:11.4.2'

문제

업데이트 한 후 앱이 전면 광고를 표시하려고 할 때마다 다운되는 것을 확인했습니다.

충돌 로그는 다음과 같습니다.

10-28 14:01:01.394 4523-4523/... I/Ads: Ad opening.
10-28 14:01:01.400 1606-2154/? E/ActivityManager: Activity Manager Crash. UID:10080 PID:4523 TRANS:63
                                                  java.lang.IllegalStateException: Only fullscreen activities can request orientation
                                                      at com.android.server.am.ActivityRecord.setRequestedOrientation(ActivityRecord.java:2189)
                                                      at com.android.server.am.ActivityManagerService.setRequestedOrientation(ActivityManagerService.java:4975)
                                                      at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:1101)
                                                      at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2927)
                                                      at android.os.Binder.execTransact(Binder.java:697)


10-28 14:01:01.403 4523-4523/... D/AndroidRuntime: Shutting down VM
10-28 14:01:01.406 4523-4523/... E/AndroidRuntime: FATAL EXCEPTION: main

java.lang.RuntimeException: Unable to start activity ComponentInfo{.../com.google.android.gms.ads.AdActivity}: java.lang.IllegalStateException: Only fullscreen activities can request orientation

문제는 이전에 잘 작동했다는 것입니다. 이제 그 원인이 무엇인지 잘 모르겠습니다.

웹을 검색 할 때 "전체 화면 활동 만 오리엔테이션을 요청할 수 있습니다."라는 내용이 표시되지 않았습니다.

내가 매니페스트에있는 것은 조금 오래되어 더 이상 필요하지 않을 수도 있습니다.

    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent"/>

내가 과거에했던 것을 기억하지만 튜토리얼에서 더 이상 볼 수 없기 때문에 아마도 필요하지 않을 것이라고 말합니다.

내가 시도한 것

  1. 매니페스트 항목을 제거하려고했습니다. 여전히 같은 문제입니다.

  2. 강제로 테마를 "@android : style / Theme.Translucent.NoTitleBar.Fullscreen"으로 설정하려고했지만 도움이되지 않았습니다.

  3. 현재 Android 8.1을 사용하고 있기 때문일지도 모른다고 생각했지만 Play 스토어에서 앱을 사용해 보았을 때 충돌없이 정상적으로 작동한다는 것을 알았습니다.

  4. 나는 admob의 11.2.2 버전으로 돌아가서 gradle v 2.3.3을 사용하려고 시도했지만 도움이되지 않았습니다.

  5. Android 7.0으로 에뮬레이터를 시도 할 때 모든 최신 버전과 전체 매니페스트 활동 태그 제거에서 제대로 작동했습니다.

  6. 내가 사용한 것 대신 gradle 파일에서 이것을 사용하려고했습니다.

    'com.google.android.gms : play-services-ads : 11.4.2'컴파일

내 기기 (Android 8.1이 설치된 Nexus 5x)에서 여전히 충돌이 발생했지만 에뮬레이터에서 충돌하지 않았습니다.

  1. 마지막으로 Android 8.1을 사용하여 에뮬레이터에서 앱을 실행하려고했는데 실제 기기에서와 마찬가지로 충돌이 발생했습니다.

  2. 이에 대해 Google Admob 팀과 Android 문제 추적기에보고했습니다 . 나는 그들이 이것에 대해 나에게 대답하기를 바랍니다.

질문

이 문제의 원인은 무엇입니까?

Android 8.1 때문인가요? 그렇다면 이전 버전의 앱이 어떻게 잘 작동합니까? 많은 버전을 이전 버전으로 되돌리려 고했지만 여전히 충돌했습니다.

그리고 가장 중요한 것은 어떻게 해결할 수 있습니까?


다음으로 업그레이드하는 것 같습니다.

com.google.firebase:firebase-ads:15.0.1

나를 위해이 문제를 해결했습니다. 방금 Nexus 5X 8.1.0에서 테스트했으며 이제 전면 광고 AdMob 광고가 작동합니다.

보다 완벽한 솔루션 :

앱의 build.gradle :

...

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        ...

        targetSdkVersion 27

        ..
    }
}

dependencies {
    ...

    implementation 'com.google.firebase:firebase-core:15.0.2'
    implementation 'com.google.firebase:firebase-ads:15.0.1'

    ...
}
apply plugin: 'com.google.gms.google-services'

최상위 build.gradle :

buildscript {
    ...

    dependencies {
        ...

        classpath 'com.google.gms:google-services:3.3.0'

        ...
    }
}

...

편집하다

이제 최신 AdMob 버전을 사용할 수 있습니다. 최신 릴리스 (15.0.1 이상)를 사용하면 문제가 더 이상 나타나지 않으므로 최신 버전의 Admob을 사용할 수 있습니다.

com.google.firebase:firebase-ads:17.1.2

이전에 제안 된 해결 방법을 사용한 경우 대상 버전을 최신으로 설정합니다.

-------------------------------------------------- --------

타겟을 Android API 레벨 26으로 설정하여 문제를 해결하고 AdMob 업데이트를 기다립니다.

build.gradle에서

targetSdkVersion 26

경우 targetSdkVersion입니다> = 27 ( > android.os.Build.VERSION_CODES.O즉 26 인)이 오류, 그들은 변경 얻을 ActivityRecord을 최신 안드로이드 버전이 추가로 :

void setRequestedOrientation(int requestedOrientation) {
        if (ActivityInfo.isFixedOrientation(requestedOrientation) && !fullscreen
                && appInfo.targetSdkVersion > O) {
            throw new IllegalStateException("Only fullscreen activities can request orientation");
        ....
        }

The change has been introduced in this commit

Prevent non-fullscreen activities from influencing orientation This changelist enforces that activities targeting O and beyond can only specify an orientation if they are fullscreen.

and probably in admob lib have messed some check


try to add this in your manifest

<activity
android:name="com.google.android.gms.ads.AdActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
tools:replace="android:theme"
 />

Or, if you are using appcompat:

<style name="TranslucentTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    etc

And in the manifest, make sure the activity is declared with

android:theme="@style/TranslucentTheme"

please do not use any properties in Android Manifest files AdActivity.

please remove this line from AdActivity in Manifest file

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"

Just simply add this following line to Android Manifest file.

    <activity android:name="com.google.android.gms.ads.AdActivity" />

If you want to set your desired activity as portrait mode please add this following line to your activities onCreate method:

if (android.os.Build.VERSION.SDK_INT != Build.VERSION_CODES.O) {
   activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

For firebase ADS 17.0.0 and upper versions use this line to manifest file.

<application
...........>

    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="@string/app_id" />

</application>

You can get app id from Admob -> Apps -> your app -> App Settings -> App Id. Please copy and paste this App_Id into your project.


This issue will Automatically be fixed when ad mob will update their ads sdk for API 27 their ads dependency do not support API 27 so due to this issue occurring.

 compile 'com.google.android.gms:play-services-ads:11.8.0'

Only full screen activities can request orientation, this is due to ads meta data in your mainfest file,admob should update their sdk for 27 version. enter image description here

if you have set target sdk version 27 then you would get this error, actually android updating sdk very fast, and some update admob left behind to do ,for integration with android sdk, so admob have pending this update, they should do this very soon ,Its not on developer side issue, if you wants to escape from this crash then set your sdk to 26.


I got the same crash with Vungle SDK (which was included through Appodeal SDK), so this does not precisely answer the question related to Admob SDK, but in case anyone's getting this with Vungle or Appodeal SDK:

The versions were as follows: Appodeal SDK - 2.4.2-220518, Vungle SDK - 6.2.5. After upgrading to the at that time newest Appodeal SDK (version 2.4.9-051218), newer Vungle SDK was included (version 6.3.12) and the crash no longer occured.


In Android Oreo You can't change the orientation by code so you have check whenever change the orientation


  if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {

                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }

참고URL : https://stackoverflow.com/questions/46992843/interstitial-admob-ads-illegalstateexception-only-fullscreen-activities-can-r

반응형