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
EDIT
Now a newer admob version is available. I confirm that using the latest releases (15.0.1 or newer) the issue doesn't appear anymore, so you can use the latest version of Admob
com.google.firebase:firebase-ads:17.1.2
setting the target version to the latest, if you have used the workaround previously suggested.
----------------------------------------------------------
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
that is 26) 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.
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"
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.
It seems that upgrading to:
com.google.firebase:firebase-ads:15.0.1
solved this issue for me. I've just tested it on Nexus 5X with 8.1.0 and Interstitial Admob ads work now.
More complete solution:
app's 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'
top level build.gradle:
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:3.3.0'
...
}
}
...
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.
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.