Interstitial Admob ads: “IllegalStateException: Only fullscreen activities can request orientation”

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

Background

I have an app with Admob SDK used in it, to show Interstitial ads (full screen ads).

Reccently Google has updated the SDK, along with many other things (build tools, gradle plugin, IDE, etc...), including admob (firebase ads).

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

The problem

After updating, I noticed that whenever the app tries to show an Interstitial ad, it crashes.

The crash log is as such:

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 

Thing is that it worked fine before. Now I'm not sure what causes it to occur.

Searching the web, I didn't see anything that talks about "Only fullscreen activities can request orientation" .

What I had in the manifest, is something a bit old, that might not be needed anymore:

    

I say it's probably not needed, because i can't see it anymore in the tutorials, even though I remember I did in the past:

What I've tried

  1. I tried to remove the manifest entry. Still same issue.

  2. I tried to set the theme to be "@android:style/Theme.Translucent.NoTitleBar.Fullscreen" by force, but it also didn't help.

  3. I even thought that it might be because I currently have Android 8.1, but when I tried using the app from the play store, I noticed it worked just fine, without crashes.

  4. I tried to go back to as far as version 11.2.2 of admob and use gradle v 2.3.3 , but it also didn't help.

  5. When trying on an emulator with Android 7.0 , it worked fine with latest versions of everything, and removal of the whole manifest activity tag.

  6. I tried to use this in gradle file, instead of what I used :

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

Still crashed on my device (Nexus 5x with Android 8.1) yet didn't crash on emulator.

  1. Finally, I tried to run the app on emulator with Android 8.1, and it crashed just as on the real device.

  2. Reported about this to Google Admob team, as well as Android issue tracker. I hope they will answer me about this.

The questions

What could be the cause to this issue?

Is it because of Android 8.1 ? If so, how come the older version of the app worked fine? I tried to revert there a lot of versions to old ones, yet it still crashed.

And, most importantly, how can I solve it?

回答1:

Set the target to Android API Level to 26 to fix the issue, waiting for Admob update

In build.gradle

targetSdkVersion 26 

if targetSdkVersion is >=27 ( > android.os.Build.VERSION_CODES.O) you get this error, they have changed ActivityRecord in latest Android version adding this:

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.



回答2:

try to add this in your manifest

Or, if you are using appcompat:

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

android:theme="@style/TranslucentTheme" 


回答3:

well it seems they still didn't update their SDK, as i am getting this problem in their latest sdk release. compile 'com.google.android.gms:play-services-ads:11.8.0'



回答4:

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.

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.



回答5:

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.

    


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!