Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After migrating to androidx: Didn't find class "androidx.constraintlayout.ConstraintLayout" on path: DexPathList

I've searched for an answer to my problem, as shown in the title of this question, and found Error inflating class androidx.constraintlayout.ConstraintLayout after migration to androidx, which aligns with the official migration instructions presented in Migrating to AndroidX. I took the information as requiring me to change android.support.constraint.ConstraintLayoutto androidx.constraintlayout.widget.ConstraintLayout, but this doesn't work for me.

I haven't found anything about what dependency to put in my gradle file, so I tried this (this is a shot in the dark):

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

which is accepted but when I tried:

    implementation 'androidx.constraintlayout.widget:constraintlayout:1.1.3'

I get ERROR: Failed to resolve: androidx.constraintlayout.widget:constraintlayout:1.1.3, so I used the previous implementation directive.

Here is my XML file:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    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"
    tools:context="com.example.jbiss.petminder.activities.MainActivity">

<!--<android.support.v7.widget.Toolbar-->
<androidx.appcompat.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="@color/colorPrimaryDark"
    android:elevation="4dp"
    app:layout_constraintTop_toTopOf="parent"
    app:popupTheme="@style/AppTheme.PopupOverlay"/>

<TextView
    android:id="@+id/tvMsg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:accessibilityLiveRegion="assertive"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.502"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/my_toolbar"
    tools:text="error message goes here"/>

<TextView
    android:id="@+id/tvEmVet"
    android:layout_width="wrap_content"
    android:layout_height="44dp"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="20dp"
    android:layout_marginTop="8dp"
    android:text="@string/emergency_vet"
    android:textColor="@android:color/holo_red_dark"
    android:textSize="24sp"
    app:layout_constraintStart_toEndOf="@+id/phoneCallEmVet"
    app:layout_constraintTop_toBottomOf="@+id/recyclerview1"
    tools:textSize="24sp"/>

<ImageView
    android:id="@+id/phoneCallEmVet"
    android:layout_width="37dp"
    android:layout_height="44dp"
    android:layout_marginBottom="8dp"
    android:layout_marginLeft="24dp"
    android:layout_marginTop="8dp"
    android:onClick="callEmVet"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/recyclerview1"
    app:srcCompat="@android:drawable/sym_action_call"/>

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerview1"
    android:layout_width="368dp"
    android:layout_height="365dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="@string/pet_name"
    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/my_toolbar"/>
</androidx.constraintlayout.widget.ConstraintLayout>

Running my app produces the following error:

2019-02-18 19:43:36.031 458-458/com.example.jbiss.petminder E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jbiss.petminder, PID: 458
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.jbiss.petminder-i-ubC_oLu_y7-aFpiqALqg==/base.apk", zip file "/data/app/com.example.jbiss

Following the information doesn't work, for some reason. The migration has been tough but I've cleaned up a lot of issues and am now unable to find a reason why this is happening when it appears that I have done what is intended.

like image 559
Jeff Avatar asked Feb 19 '19 02:02

Jeff


3 Answers

I solved my problem. I found that Androidx migration is a bit more involved than I had at first thought. Knowing that I had updated the labels of the ConstraintLayout elements in the XML files used in the initial screen, I used Windows GREP to search for "android.support.constraint.ConstraintLayout" throughout my project. Lo and behold I found instances that I had missed and so I updated the XML file reference to "androidx.constraintlayout.widget.ConstraintLayout".

This allowed my project to be successfully built and launch on the emulator. However, after trying to access another screen I got the same error as shown in my initial post, but for the AppBarLayout. So, I must proceed for this one as I did for ConstraintLayout and then any others.

If you are migrating, be prepared for a little more work than you had anticipated!

like image 72
Jeff Avatar answered Nov 11 '22 02:11

Jeff


I was facing the same problem after migrating to androidX. Tried above solution. But, it didn't work. I added mavenCentral() in project level app gradle.

 repositories {
            jcenter()
            maven { url 'https://maven.google.com' }
            mavenCentral()
     }

with following changes

dependencies  {
    implementation 'com.google.android.material:material:1.0.0'
    implementation "androidx.constraintlayout:constraintlayout:1.1.3"
}

updated "android.support.constraint.ConstraintLayout" xml tag with "androidx.constraintlayout.widget.ConstraintLayout"

finally it worked.

like image 44
Sadia Tasnim Swarna Avatar answered Nov 11 '22 04:11

Sadia Tasnim Swarna


If you experience this issue on Android Studio 3.6.3 after using the Migrate to Androidx tool like I did, Here is what worked for me:

I was using androidx.constraintlayout.ConstraintLayout in my layout XML file instead of androidx.constraintlayout.widget.ConstraintLayout

The difference is one has widget before ConstraintLayout. The dependency in my app-level build.gradle was:

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

The latest at that time.

like image 3
Eaweb Avatar answered Nov 11 '22 03:11

Eaweb