Error inflating class androidx.constraintlayout.ConstraintLayout after migration to androidx

后端 未结 17 1160
[愿得一人]
[愿得一人] 2020-11-27 14:24

I just made a migration to androidx through Android Studio menu option Refactor -> Refactor to AndroidX

I\'m getting the following

相关标签:
17条回答
  • 2020-11-27 14:48

    Make sure to change to

    <androidx.constraintlayout.widget.ConstraintLayout
    

    instead of

    <android.support.constraint.ConstraintLayout
    

    and

    <androidx.constraintlayout.widget.Barrier
    

    instead of

    <android.support.constraint.Barrier
    
    0 讨论(0)
  • 2020-11-27 14:54

    Add androidx.constraintlayout.widget.ConstraintLayout to the dependencies:

    dependencies  {
        // https://mvnrepository.com/artifact/androidx.constraintlayout/constraintlayout
        implementation "androidx.constraintlayout:constraintlayout:1.1.3"
    }
    

    It's available on mavenCentral().

    0 讨论(0)
  • 2020-11-27 14:55

    After clicking on Refactor -> Migrate to AndroidX , Make sure your all dependencies in the build.gradle(Module:app) is marked to the newest version.

    If its not, dependency will appear in yellow highlighted color and you can change it by hovering the mouse over it.

    Secondly, Change the ConstraintLayout tag in all XML layout files to

    androidx.constraintlayout.widget.ConstraintLayout

    For more safer option, clean your project and sync it again after the above steps.

    0 讨论(0)
  • 2020-11-27 14:56

    I had this issue with Android Studio 4.0. I used android studio 4.0 for a couple of days without problems. Seemingly out of nowhere the designer view stopped working. I could only fix this by uninstalling android studio and installing the newest android studio version.

    0 讨论(0)
  • 2020-11-27 14:59

    make sure your project migrate to androidx completely , In my case I found :

    <android.support.constraint.ConstraintLayout
    

    instead of

      <androidx.constraintlayout.widget.ConstraintLayout
    

    So change it and my problem fixed!

    0 讨论(0)
  • 2020-11-27 14:59

    I had a similar error.

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayout
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2757)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2818)
            at android.app.ActivityThread.-wrap12(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1557)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:163)
            at android.app.ActivityThread.main(ActivityThread.java:6393)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
        Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayout
        Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayout
        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:652)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:812)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:752)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
            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 com.myapp.MainActivity.onCreate(MainActivity.java:23)
            at android.app.Activity.performCreate(Activity.java:6858)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2710)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2818)
            at android.app.ActivityThread.-wrap12(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1557)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:163)
            at android.app.ActivityThread.main(ActivityThread.java:6393)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
        Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/constraintlayout/widget/R$styleable;
            at androidx.constraintlayout.widget.ConstraintLayout.init(ConstraintLayout.java:590)
            at androidx.constraintlayout.widget.ConstraintLayout.<init>(ConstraintLayout.java:567)
            ... 23 more
        Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.constraintlayout.widget.R$styleable" on path: DexPathList[[zip file "/data/app/com.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp-1/lib/arm64, /system/lib64, /vendor/lib64]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
            ... 25
    

    Following the recomendations:

    add androidx.constraintlayout.ConstraintLayout to the dependencies:
    
    dependencies  {
        implementation "androidx.constraintlayout:constraintlayout:1.1.3"
    }
    

    And the repository mavenCentral().

    Works for me. I could compile the APK.

    0 讨论(0)
提交回复
热议问题