15

the error is triggered by the command:

setContentView(R.layout.activity_item_list);

this code was generated by android studio , when creating a new android project using the "master/slave flow"

it seems the layout was rendered but still the errors appear

I/zygote: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
        at void android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, android.support.v4.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)
        at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)
        at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
        at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
        at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
        at void com.junkradar.junkradar.ItemListActivity.onCreate(android.os.Bundle) (ItemListActivity.java:52)
        at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7009)
        at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7000)
        at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1214)
        at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2731)
        at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2856)
        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:1589)
        at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
        at void android.os.Looper.loop() (Looper.java:164)
        at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6494)
        at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
        at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:438)
        at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:807)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/base.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_dependencies_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_resources_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_slice_0_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_slice_1_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_slice_2_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_slice_3_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_slice_4_apk.apk", zip file "/data/app/com.junkradar.junkradar-g7TqmgFV3I4lrTx3ge5E_g==/split_lib_slice_5_apk.apk", zip file "/data/app/com.jun
        at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:125)
        at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
        at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
        at void android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, android.support.v4.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)
        at android.view.ViewGroup .....

activity_item_list.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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:context=".ItemListActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <include layout="@layout/item_list" />
    </FrameLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>

as mentioned, the code is generated automatically by Android Studio 3.2.1 and selecting "Master/Detail Flow" type of Activity

Dror
  • 5,107
  • 3
  • 27
  • 45
  • can you show your activity_item_list xml file? – Jawad Malik Nov 05 '18 at 19:42
  • there's a problem in that file maybe – Jawad Malik Nov 05 '18 at 19:42
  • @JawadMalik I doubt the file has an issue. it is autogenerated by Android Studio. I attached the code. it references an "include layout="@layout/item_list" which couldn't be pasted, but the file is very basic recyclerView, which points to another Card_View. all are part of the "Master/Detail flow" template of android studio – Dror Nov 05 '18 at 21:00
  • it looks like this but sometimes there comes an issue which Android Studio also don't notify – Jawad Malik Nov 07 '18 at 16:21
  • @Dror Have you solved the issue?? – Sino Nov 09 '18 at 07:12
  • @SinoKD yes. just marked it as solved – Dror Nov 09 '18 at 22:08
  • @SinoKD I used the code below. also there's a reference that might be relevant as well - https://developer.android.com/studio/build/multidex – Dror Dec 22 '18 at 21:45

1 Answers1

9
  1. I stumbled on a github snippet that does the trick

you should paste the following to the bottom of your project's - build.gradle

// This is to fix the errors : java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
configurations.all {
    resolutionStrategy.eachDependency { details ->
        def requested = details.requested
        if (requested.group == "com.android.support") {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion "26.+"
            }
        }
    }
}
  1. i ended up using the suggestion in the URL below (instead of 1) -

developer.android.com/studio/build/multidex

Dror
  • 5,107
  • 3
  • 27
  • 45
  • @Bobert try bullet 2 instead – Dror Feb 07 '19 at 18:10
  • 1
    For Androidx replace "com.android.support" by "androidx" – FireZenk Feb 14 '19 at 15:24
  • @Bobert Read the answer [here](https://stackoverflow.com/a/42957234/1770778). In the comment it says just to remove `DependencyResolveDetails` coz the type declaration is not needed. Worked for me. – ffonz Apr 10 '19 at 17:10
  • @Dror What do these lines do? I'm affraid to write this without understanding it. – JarsOfJam-Scheduler Jul 08 '19 at 20:06
  • 1
    @JarsOfJam-Scheduler forces all your dependancies to use the same support library version – Luke Brandon Farrell Jul 15 '19 at 12:59
  • What suggestion from that URL did you use? – AlexVPerl Aug 22 '19 at 03:56
  • @AlexVPerl see under the title "Configure your app for multidex", but it's irrelevant if you use minSdkVersion is set to 21 or higher – Dror Aug 22 '19 at 05:44
  • @Dior thanks. I tried both 1 & 2 and both resolve the warning. I'm a bit puzzled though as to why #1 works. #2 makes sense because of dex'ing, a dependency probably was not in the initial dex file used for app startup. But #1 sets version=26 for all support libs besides multidex lib - have you been able to find out why #1 works? – AlexVPerl Aug 23 '19 at 02:15
  • @AlexVPerl don't know why, i'm afraid. i didn't have the time to dig deeper – Dror Aug 24 '19 at 09:19