Crash with java.lang.NoClassDefFoundError after migrating to AndroidX : <p>I'm trying to compile and run a demo app that was written for an old Android version.</p>

<p>I have updated all the files to use the new androidx libraries. That included the gradle.build the manifest and layout files.
It compiles properly but crashes on the main activity on <code>setContentView(R.layout.activity_main);</code></p>

<p>From looking at the stack trace I can deduce that its related to the layout.xml file as the app crash when it set for the first time.
But I could not find any problem with the layout file after migrating the FloatingActionButton from the old to the new deisgn librarey.</p>

<p>Any ideas?</p>

<p>Stack:</p>

<pre><code>I/zygote: Rejecting re-init on previously-failed class java.lang.Class&lt;androidx.core.view.ViewCompat$2&gt;: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
        at void androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, androidx.core.view.OnApplyWindowInsetsListener) (ViewCompat.java:2423)
        at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:750)
        at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:630)
        at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:529)
        at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:161)
        at void com.example.android.emojify.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:75)
        at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6975)
        at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1213)
        at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2770)
        at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2892)
I/zygote:     at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
        at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1593)
I/zygote:     at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:105)
        at void android.os.Looper.loop() (Looper.java:164)
        at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6541)
        at java.lang.Object 
</code></pre>

<p>build.gradle:</p>

<pre><code>apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.android.emojify"
        minSdkVersion 26
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.google.android.material:material:1.1.0-alpha07'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.gms:play-services-vision:17.0.2'
    implementation 'com.jakewharton:butterknife:10.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
    implementation 'com.jakewharton.timber:timber:4.7.1'
    testImplementation 'junit:junit:4.12'
}
</code></pre>

<p>and layout file:</p>

<pre><code>&lt;RelativeLayout 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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.android.emojify.MainActivity"&gt;

    &lt;ImageView
        android:id="@+id/image_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/view_margin"
        android:contentDescription="@string/imageview_description"
        android:scaleType="fitStart" /&gt;

    &lt;TextView
        android:id="@+id/title_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/emojify_button"
        android:layout_centerHorizontal="true"
        android:layout_margin="@dimen/view_margin"
        android:text="@string/emojify_me"
        android:textAppearance="@style/TextAppearance.AppCompat.Display1" /&gt;

    &lt;Button
        android:id="@+id/emojify_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/go"
        android:textAppearance="@style/TextAppearance.AppCompat.Display1"/&gt;

    &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/clear_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/ic_clear"
        android:visibility="gone"
        app:backgroundTint="@android:color/white"
        app:fabSize="mini" /&gt;

    &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/save_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="@dimen/fab_margins"
        android:layout_marginEnd="@dimen/fab_margins"
        android:layout_marginRight="@dimen/fab_margins"
        android:src="@drawable/ic_save"
        android:visibility="gone"
        app:backgroundTint="@android:color/white" /&gt;

    &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/share_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="@dimen/fab_margins"
        android:layout_marginLeft="@dimen/fab_margins"
        android:layout_marginStart="@dimen/fab_margins"
        android:src="@drawable/ic_share"
        android:visibility="gone"
        app:backgroundTint="@android:color/white" /&gt;

&lt;/RelativeLayout&gt;
</code></pre>
