Yugraaj Sandhu
Yugraaj Sandhu

Reputation: 434

Android fragments ClassNotFoundException: Didn't find class android.support.constraint.ConstraintLayout

The activities working fine even the newly create fragments work, but if i go to the old fragment classes the app stops working and i can see the error in console :

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.singeek.nav.pmcalculator/com.singeek.nav.pmcalculator.OptionActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2805)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6523)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
     Caused by: 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.singeek.nav.pmcalculator--icu9YauYQyfz4UoNRwBLQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.singeek.nav.pmcalculator--icu9YauYQyfz4UoNRwBLQ==/lib/arm64, /system/lib64, /vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.view.LayoutInflater.createView(LayoutInflater.java:606)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.singeek.nav.pmcalculator.OptionActivity.onCreate(OptionActivity.java:16)
        at android.app.Activity.performCreate(Activity.java:7023)
        at android.app.Activity.performCreate(Activity.java:7014)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2758)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6523)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)

But also in fragment's XML layout file i see the following errors:

The following classes could not be found: - android.support.constraint.ConstraintLayout (    Add constraint-layout library dependency to the project, Fix Build Path, Edit XML, Create Class) Tip: Try to build the project.

Following is build.gradle file:

apply plugin: 'com.android.application'   //added when firebase connected
apply plugin: 'com.google.gms.google-services'     //added when firebase connected

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.singeek.nav.bakercalculator"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 3
        versionName "1.2"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            //    useProguard true
            shrinkResources true
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }
}

dependencies {
    androidTestImplementation 'junit:junit:4.12'
    testImplementation 'junit:junit:4.12'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    // implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta5"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.github.hotchemi:android-rate:1.0.1'
    implementation 'com.google.firebase:firebase-auth:19.3.1'   //added when firebase connected
    implementation 'com.google.android.gms:play-services-auth:18.0.0'
    implementation 'com.facebook.android:facebook-login:[5,6)'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

}

XML layout file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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=".FragmentA">

    <!-- TODO: Update blank fragment layout -->

    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <EditText
                android:id="@+id/doughNameBox"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:hint="@string/enter_recipe_name"
                android:inputType="textPersonName" />

            <TableLayout
                android:id="@+id/ingredientTable"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:stretchColumns="0,1">

            </TableLayout>

            <Button
                android:id="@+id/add_ingredient"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:autoSizeMaxTextSize="12dp"
                android:autoSizeMinTextSize="2dp"
                android:autoSizeTextType="uniform"
                android:background="@color/colorPrimary"
                android:drawableLeft="@drawable/ic_plus"

                android:singleLine="true"
                android:text="Add Ingredient"
                android:textColor="@android:color/white"

                />

            <Button
                android:id="@+id/generateButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/generateButton" />
        </LinearLayout>
    </ScrollView>

</android.support.constraint.ConstraintLayout>

Upvotes: 0

Views: 109

Answers (1)

Gautam
Gautam

Reputation: 3362

Since you are using androidx, kindly use this path -

androidx.constraintlayout.widget.ConstraintLayout

Upvotes: 1

Related Questions