java.lang.NoClassDefFoundError: android/graphics/drawable/Icon
Asked Answered
K

4

95

So far I got this error only for one user, who uses a rooted phone (SM-G900R7 Android 4.4.2). The error is like this:

Fatal Exception: java.lang.NoClassDefFoundError: android/graphics/drawable/Icon
       at java.lang.Class.getDeclaredMethods(Class.java)
       at java.lang.Class.getDeclaredMethods(Class.java:656)
       at android.view.ViewDebug.getExportedPropertyMethods(ViewDebug.java:960)
       at android.view.ViewDebug.exportMethods(ViewDebug.java:1047)
       at android.view.ViewDebug.dumpViewProperties(ViewDebug.java:997)
       at android.view.ViewDebug.dumpViewProperties(ViewDebug.java:983)
       at android.view.ViewDebug.dumpView(ViewDebug.java:900)
       at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:870)
       at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:867)
       at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:867)
       at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:867)
       at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:867)
       at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:867)
       at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:867)
       at android.view.ViewDebug.dumpViewHierarchy(ViewDebug.java:867)
       at android.view.ViewDebug.dump(ViewDebug.java:793)
       at android.view.ViewDebug.dispatchCommand(ViewDebug.java:416)
       at android.view.ViewRootImpl$W.executeCommand(ViewRootImpl.java:6258)
       at android.view.IWindow$Stub.onTransact(IWindow.java:65)
       at android.os.Binder.execTransact(Binder.java:404)
       at dalvik.system.NativeStart.run(NativeStart.java)

I never use android.graphics.drawable.Icon in my code, all usages are from android.support.v4.graphics.drawable.IconCompat and I also never use that class in my code...

Btw my support library is version 26.0.0, my minSdkVersion is 15 targetSdkVersion is 26.

Thanks

Korey answered 9/8, 2017 at 5:39 Comment(19)
You can check this answer https://mcmap.net/q/225206/-noclassdeffounderror-for-okhttpclientLillian
Same issue for me. Same rooted device, same android version. Did you find a solution?Domingodominguez
Same issue for me. Not all devices rooted, but same Samsung device and android version. :(Fanning
No, i didn't try the solutions which are post here, there is also no more error report, maybe that user deleted my app..Korey
Let me guess? Samsung devices running Android 4?Bellboy
Same exceptions, same device here.Yettayetti
@NomanRafique Samsung S5, 4.4.2, rooted.Bandeau
One user of my app is getting this problem... Multidex works?Replete
I'm experiencing the same thing, same device reported via crashlyitcs. One instance almost every new version, and almost immediately after publishing. My app has multidex.Nims
Got this crash today on a rooted Galaxy S5 running 4.4.2. I'm using AppCompat 26.0.2, compileSdkVersion 26, targetSdkVersion 26.Ambert
Same crash on non rooted Galaxy S5 running 4.4.2. AppCompat 26.0.2 targetSdkVersion 26Presbyopia
Also seeing the same issue.. 55 users (according to Crashlytics) and ALL of them S5 running 4.4.2..Pius
Indeed: Samsung Galaxy S5. Android 4.4.2. Rooted. Not sure if they get the issue again for relaunching the app, or these users just uninstall the app and leave.Typhoid
Same issue for me. Has anyone found the solution yet?Leblanc
ditto users w/ an S5 running 4.4.2...gotta be something Samsung screwed up in that version of the OS :-PFedak
google issue tracker: issuetracker.google.com/issues/63151548Kneepad
I commit a PR to AOSP to fix this issue. android-review.googlesource.com/#/c/platform/frameworks/support/… <br>Before this PR being merged, I have to take the same way with phnmnn.Westberg
According the issuetracker (issuetracker.google.com/issues/63151548), the problem is resolved once you update to 27.0.0 support libKneepad
I am experiencing a similar issue with android.view.ViewStructure (instead of Icon). I've seen it with 26.0.2 and also 27.0.0. I get only one crash in Crashlytics from Galaxy S5 with 4.4.2 (but the user base is quite small due to the rollout).Kinslow
D
39

Update

The issue is fixed in support library 27.0.0. If you update don't forget to change compileSdkVersion 27 as well.

What is happening?

Samsung devices with Android 4.4 crash like this when classes extending View define methods which return or take parameters of types that are not on classpath.

Starting with support library version 25.4.0 AppCompatImageView and AppCompatImageButton incorrectly overrides setImageIcon(Icon) method. Since Icon class was introduced in API 23 the app crashes on Samsung devices with API 19.

Similar thing happens when you try to override View.onApplyWindowInsets(WindowInsets).

Workaround for support library 26.1.0

Until this gets fixed in an official manner, If you're stuck with an older version of the support library, I made a modified version of appcompat-v7 where all traces of setImageIcon methods are removed. This means it won't crash on a Samsung with Android 4.4.

Put this at the bottom of your app's build.gradle:

repositories {
    maven { url "https://dl.bintray.com/consp1racy/maven" }
}

configurations.all {
    resolutionStrategy.eachDependency { details ->
        def requested = details.requested
        if (requested.group == 'com.android.support' && requested.name == 'appcompat-v7') {
            details.useTarget 'net.xpece.android:support-appcompat-v7-fixed:26.1.0-1'
        }
    }
}

This code will replace appcompat-v7 dependency with the described modified artifact.

Currently the only supported version of the fix is 26.1.0.

Warning: Understand the code before copy-pasting, and always exercise caution when getting code from unknown sources!

Durra answered 14/10, 2017 at 22:10 Comment(12)
what will happen in the future if I must update the support library to > 26.1.0? I think your fix will be obsolete, right?Bobbery
@Bobbery No worries, it should be fixed in the next release.Durra
I'm using 26.0.2 and got this crash. Will your fix work on that version?Calyptrogen
@Calyptrogen Don't use multiple versions of different support libraries. I think you can safely update all your support libs to 26.1.0. The fix is only released for that one version.Durra
I'm not, why the advice though? I will update and use your fix, thanksCalyptrogen
@Calyptrogen it's just force of habit. Many people don't know that support libraries are interconnected and may crash if different versions are used. Just making sure that you do :)Durra
It is not fixed in the support lib 27.0.0 After app update I got the same crash in crashlytics with target 27, compile 27, and support lib 27.0.0Toothed
@Toothed I just went through the source of AppCompat 27.0.0 and it is correct. Two options: 1) Somehow you're still using older support library. Check your resolved dependencies. 2) The same exception is thrown elsewhere and because of a different class. Can you share the crash report or the stack trace? I'll look into it.Durra
Sorry for the confusion. I have a similar issue, but somewhere else (ViewDebug.dumpviewProperties). I didn't pay enough enough attention, it was too early. Thank you pointing out my mistakeToothed
@Toothed It's the same exception and the same reason - using new classes in view methods on old devices. Can you pinpoint it to your own code? Otherwise it may have come from another place in support library. In that case I'd like to see the first line, the one that says which class was referenced.Durra
@EugenPechanec Can't pinpoint it. Based on the crashlytics log it doesn't link to any specific part of our code. Caused by java.lang.ClassNotFoundException: Didn't find class "android.view.ViewStructure" on path: ... The device i got the report from is a Samsung S5 running 4.4.2 and possibly rooted. Tired to reproduce it on both Android Emulator and Genymotion and couldn't. For us the issue is happening for only one user, also happened once, so maybe he/she stopped trying or it doesn't crash anymore?!? but usually after every update I can see crash coming up and I hate unfixed crashes...Toothed
If you're having trouble after changing the sdk version, it might help to 'clean project' and try againWoodard
F
14

This issue was resolved in support library 27.0.0:

Android Gradle Plugin 3.x:

implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:support-v4:27.0.0'

Android Gradle Plugin 2.x:

compile 'com.android.support:appcompat-v7:27.0.0'
compile 'com.android.support:support-v4:27.0.0'

Note that you will also need to compile against SDK level 27.

Felly answered 26/10, 2017 at 13:2 Comment(0)
I
1

This crash related to 25.4.0 version of support library.

Use 25.3.1 version.

Replace

compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:support-v4:25.4.0'

With:

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
Iulus answered 2/10, 2017 at 14:16 Comment(1)
Worth noting that this locks you down to compileSdkVersion 25, no Android O APIs and no support library features introduced since 25.4.0 (e.g. tinting image view drawables and vector path morphing backport). Here's the support library changelog developer.android.com/topic/libraries/support-library/…Durra
N
-1

There are 2 options :

  1. Have you changed the support library version ? this is quite classic library issue when the resources sometimes aren't 'saved' with the same name, or at all. Its not you, its google. Try to use support lib 25, and see if this error still occurs.
  2. Try to clean the project and rebuild. Maybe you're kept with some old library versions in your build folder, and when you build your project it takes old values from it.
Nilson answered 9/8, 2017 at 7:19 Comment(4)
thank you for answer, for 2. I did full gradle clear many times. for 1. my targetSdkVersion is 26, Android Studio shows warn if not target the newest API and Android Studio also shows error if I use older version of support lib than targetSdkVersion.Korey
Same problem after updating to SDK 26.Gastight
@Korey which version of support library are you using?Galway
@Gastight and your support lib version is?Galway

© 2022 - 2024 — McMap. All rights reserved.