Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error inflating class after migration to androidx

I 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
 Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout

I studied all the resources and migrated to Androidx, but I still have a lot of problems. Can someone help me? I will post the sections of the code below.

--------- beginning of crash ---------

2019-01-23 09:47:34.171 17578-17578/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ir.bijac.com.bijac, PID: 17578
    java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.bijac.com.bijac/ir.bijac.com.bijac.TestActivity}: android.view.InflateException: Binary XML file line #12: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     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)
        at android.app.Activity.performCreate(Activity.java:6679)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/coreui/R$attr;
        at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:202)
        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) 
        at android.app.Activity.performCreate(Activity.java:6679) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6119) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
2019-01-23 09:47:34.171 17578-17578/? E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.coreui.R$attr" on path: DexPathList[[zip file "/data/app/ir.bijac.com.bijac-2/base.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_dependencies_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_0_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_1_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_2_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_3_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_4_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_5_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_6_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_7_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_8_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/ir.bijac.com.bijac-2/lib/x86, /system/lib, /vendor/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
            ... 27 more

build gradle:

apply plugin: 'com.android.application'
repositories {
    mavenCentral()
}

android {
    useLibrary 'org.apache.http.legacy'
    compileSdkVersion 28
    defaultConfig {
        applicationId "ir.bijac.com.bijac"
        minSdkVersion 18
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.1.0-alpha02'
    implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.test.espresso:espresso-core:3.1.1'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestUtil 'androidx.test:orchestrator:1.1.1'
    configurations.all { resolutionStrategy.force 'com.android.support:support-v4:28.0.0' }
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.nineoldandroids:library:2.4.0'
    implementation 'com.daimajia.slider:library:1.1.5@aar'
    implementation "cz.msebera.android:httpclient:4.4.1.2"
    implementation 'org.apache.httpcomponents:httpcore:4.4.10'
    implementation 'com.androidadvance:topsnackbar:1.1.1'
    implementation 'co.ronash.android:pushe-base:1.4.1'
    implementation 'com.google.android.gms:play-services-gcm:16.0.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
        transitive = true;
    }

}

--------- activity_main.xml ---------

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start"
    >

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
like image 695
hassan abbasi Avatar asked Jan 23 '19 06:01

hassan abbasi


2 Answers

You are likely to have a reference to android.support.design.widget.CoordinatorLayout in some of your xml layout files.

Press CTRL + SHIFT + F or go to Edit/Find/Find in Path and just search for android.support.design.widget.CoordinatorLayout and replace it with androidx.coordinatorlayout.widget.CoordinatorLayout.

You may use CTRL + SHIFT + R or Edit/Find/Replace in Path instead to replace all matches at once.

like image 152
Fran Marzoa Avatar answered Oct 01 '22 10:10

Fran Marzoa


in XML file, replace

androidx.appcompat.widget.RecyclerView

with:

androidx.recyclerview.widget.RecyclerView
like image 26
Ali Has Avatar answered Oct 01 '22 08:10

Ali Has