Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error inflating class android.support.design.widget.CoordinatorLayout after migration to androidx

I just made a migration to Androidx but after the migration, I'm getting the following error:

Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout`

Any idea?

Stacktrace:

 Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
 Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
    at android.view.LayoutInflater.createView(LayoutInflater.java:645)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:964)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
    at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
    at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at ir.bijac.com.bijac.BaseActivity.onCreate(BaseActivity.java:43)
    at ir.bijac.com.bijac.TestActivity.onCreate(TestActivity.java:22)
        compileSdkVersion 28
        minSdkVersion 18
        targetSdkVersion 28


dependencies {
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
} ```



like image 380
delete27 Avatar asked Feb 04 '26 12:02

delete27


1 Answers

I had a similar experience after migrating to Androidx. I resolved the issue following these steps: [1] Ensure that the layout file uses this

 <androidx.coordinatorlayout.widget.CoordinatorLayout>

 </androidx.coordinatorlayout.widget.CoordinatorLayout>

[2] Follow this step if Android studio did not change the support libraries imports after migration to Androidx.

Go to the class file(java or kt), DELETE all imports related to the former libraries and allow Android Studio to import the appropriate Androidx libraries. Do these for all other migration issues.

This is what your dependencies should look like:

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.drawerlayout:drawerlayout:1.0.0' //DrawerLayout
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
implementation 'com.google.android.material:material:1.0.0' //androidx AppBarLayout, CollapsingToolbarLayout etc.
implementation 'androidx.webkit:webkit:1.0.0' //androidx webview
like image 155
leeCoder Avatar answered Feb 06 '26 02:02

leeCoder