30

Facebook SDK version 4.27.0

Android OS version 8.0

App crashes with exception, this is the trace log I have found over Crashlytics:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.yyy/com.facebook.FacebookActivity}: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2822)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897)
       at android.app.ActivityThread.-wrap11(Unknown Source)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:251)
       at android.app.ActivityThread.main(ActivityThread.java:6563)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
       at android.app.Activity.onCreate(Activity.java:986)
       at android.support.v4.app.SupportActivity.onCreate(SupportActivity.java:66)
       at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:285)
       at com.facebook.FacebookActivity.onCreate(FacebookActivity.java:62)
       at android.app.Activity.performCreate(Activity.java:6975)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2775)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897)
       at android.app.ActivityThread.-wrap11(Unknown Source)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:251)
       at android.app.ActivityThread.main(ActivityThread.java:6563)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Can anyone help me with this ?

PS: In Android Source, after looking at this line number 987, it seems that this line is the culprit.

https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/app/Activity.java#1002

Also, in my manifest:

<activity
    android:name="com.facebook.FacebookActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name"
    android:screenOrientation="portrait" />
Chintan Soni
  • 24,761
  • 25
  • 106
  • 174

7 Answers7

37

Removing this attribute:

android:screenOrientation="portrait"

from FacebookActivity tag, may solve the problem.

Chintan Soni
  • 24,761
  • 25
  • 106
  • 174
  • I haven't added above line in `FacebookActivity` but if `trus` is present in your style then you have to remove that and its worked – Ninja Oct 22 '18 at 10:57
3

From the latest fb integration guide, we don't need to specify either theme or orientation that is causing crash on android 8.0 . So we should use latest fb sdk with their new settings:

<activity android:name="com.facebook.FacebookActivity"
    android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name" />

https://developers.facebook.com/docs/facebook-login/android/#manifest

thanhbinh84
  • 17,876
  • 6
  • 62
  • 69
2

When i removed this <item name="android:windowIsTranslucent">true</item> from style problem was solved.

Yuri Misyac
  • 4,364
  • 2
  • 16
  • 32
0

remove this line from your style menu

  <item name="android:windowIsTranslucent">true</item>
0

Changed

<style name="AppTheme" parent="android:Theme.Translucent.NoTitleBar"></style>`

to

 <style name="AppTheme" parent="android:Theme.Holo.NoActionBar.TranslucentDecor"></style>

then remove

<item name="android:windowIsTranslucent">true</item>
fevziomurtekin
  • 192
  • 1
  • 3
  • 10
0

In Android O and later this error happens when you set

 android:screenOrientation="portrait"

This code is written in the AndroidManifest file:

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

Remove this from manifest file

android:screenOrientation="portrait"

and add below code to activity in oncreate before setContentView :

 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

This will fix illegalStateException issue/

Rizwan
  • 1,461
  • 12
  • 26
0

In the Facebook Developer documentation :

If you use version 5.15 or later of the Facebook SDK for Android, you don't need to to add an activity or intent filter for Chrome Custom Tabs. This functionality is included in the SDK.

The problem is caused by :

android:screenOrientation="portrait"

and the presence of :

<item name="android:windowIsTranslucent">true</item>

So if you remove this declaration from your Manifest, it should works:

<activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:screenOrientation="sensorPortrait" android:label="@string/app_name"/>
    
<activity android:name="com.facebook.CustomTabActivity" android:screenOrientation="sensorPortrait" android:exported="true">
  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="@string/fb_login_scheme" />
  </intent-filter>
</activity>
Badr Yousfi
  • 215
  • 3
  • 9