Error inflating class com.facebook.login.widget.LoginButton on FacebookSdk 5.8.0

Artem Mihelson
2 min readApr 15, 2021

There is a story behind all of this, but I think I can skip it and procced directly to the issue.

The issue is the following… If to be more precise, there are more than one issue with Facebook Login button integration. One of them is the outdated documentation Facebook provides during the Login Button integration.

In the documentation they write this:

implementation ‘com.facebook.android:facebook-android-sdk:[4,5)’

While the latest one is this:

implementation ‘com.facebook.android:facebook-android-sdk:5.8.0’

Also, in documentation they write that you need to initialize facebook sdk in your application, like this:

@Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
}

While currently you don’t have to use sdkInitialize, especially when it is already deprecated by Facebook itself. Instead, SDK is initialized by itself automatically. Facebook adds FacebookInitProvider to AdroidManifest.xml to simplify developer’s life (better update your documentation, Facebook!).

Now, after you add your LoginButton to your layout.xml, everything compiles fine and app is run successfully… until you open the activity with the login button. Once you do, your app got crashed with the following exception:

Error inflating class com.facebook.login.widget.LoginButton

“WTH?” — I thought. “This must be a joke. I can go to the class and read it (as much as allowed). Why error?”

The answer is this: once you include libraries to your project, the number of function increases. And I believe Facebook library is really heavy, that is why my project got exceeded the 56635 DEX limit.

In order to resolve this situation, just enable MULTIDEX!

Here is how to do (for android sdk 21+, in app mudule build.gradle file):

defaultConfig{
minSdkVersion 21
targetSdkVersion 29
versionCode 12
versionName “2.0”

testInstrumentationRunner “androidx.test.runner.AndroidJUnitRunner”
multiDexEnabled true
}

Hope for someone this little how-to will be helpful! Stay healthy!

--

--

Artem Mihelson

Founder of Pills.Kit, Proximodoro and WidgetLingo apps