The InflateException of Death

AppCompat Library woes in Android

Raju K
XRPractices
2 min readMay 16, 2020

--

If you are developing an android application that uses “Android Support Library” which Android SDK calls as “AppCompat”, most likely that you will be using the recent one which is “androidx”. If your application doesn’t depend on any third-party libraries, it is most likely that your app will work like breeze.

But the problem arises, when you tend to use third party components within your app. Especially if the third party components use one of the many AppCompat libraries that are out there in android. Recently one such incident occurred where a Toolbar component contained in an external library kept on throwing “InflateException”.

The stack trace was not that helpful though. The only hint was that it gave was, it is failing while inflating DrawerLayout widget which contains a Toolbar component within it. The further stack traces hinted that the Toolbar component was unable to fetch a specific theme attribute value from the resources. After struggling a bit, we could able to trace the root of the problem.

Weirdly enough Android has many versions of AppCompat libraries, v4, v7, v13, and androidx. My host app was using AppCompat v7. Also, I could figure out that the AppCompat library in which the third party library was using AppCompat v4 library (To basically have backward compatibility as old as Android 4.0). Here’s the set of changes that I had to make in my project to get the InflateException to go away and have the third party application work as expected.

In the build.gradle file, removed all references to other appcompat libraries and added only the V4 library

Made my MainActivity to extend from andoid.app.Activity (Earlier it was extending v7 AppCompatActivity). Removed the imports of v7 appcompat.

Modified my AppTheme to use “android:Theme.Holo.Light” in values/styles.xml

Recompiled the application and Voila! the InflateException vanished in thin air and could able to get the third party library work as expected.

--

--

Raju K
XRPractices

Innovator | XR | AR | VR| Robotics Enthusiast | Thoughtworks