41

I have updated the AppCompat libraries to 24.2.1 and the SDK to Android 7 in my Eclipse install. Since that, I'm not capable to run any of my apps. I appreciate if you can help a bit with that...

E/AndroidRuntime(17555): java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/os/BuildCompat;
E/AndroidRuntime(17555):    at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:196)
E/AndroidRuntime(17555):    at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:181)
E/AndroidRuntime(17555):    at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:521)
E/AndroidRuntime(17555):    at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
E/AndroidRuntime(17555):    at com.ryosoftware.calendareventsnotifier.MainActivity.onCreate(MainActivity.java:844)
E/AndroidRuntime(17555):    at android.app.Activity.performCreate(Activity.java:5990)
E/AndroidRuntime(17555):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
E/AndroidRuntime(17555):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
E/AndroidRuntime(17555):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
E/AndroidRuntime(17555):    at android.app.ActivityThread.access$900(ActivityThread.java:154)
E/AndroidRuntime(17555):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
E/AndroidRuntime(17555):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(17555):    at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(17555):    at android.app.ActivityThread.main(ActivityThread.java:5294)
E/AndroidRuntime(17555):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17555):    at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(17555):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
E/AndroidRuntime(17555):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
E/AndroidRuntime(17555): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.os.BuildCompat" on path: DexPathList[[zip file "/data/app/com.ryosoftware.calendareventsnotifier-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E/AndroidRuntime(17555):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(17555):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(17555):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(17555):    ... 18 more
E/AndroidRuntime(17555):    Suppressed: java.lang.ClassNotFoundException: android.support.v4.os.BuildCompat
E/AndroidRuntime(17555):        at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(17555):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(17555):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(17555):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(17555):        ... 19 more
E/AndroidRuntime(17555):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
The Matrix
  • 1,268
  • 2
  • 14
  • 23
  • Check this 1. Right click on your project and select Properties. 2. Select Java Build Path from the menu on the left. 3. Select the Order and Export tab. 4. From the list make sure the libraries or external jars you added to your project are checked. 5. Finally, clean your project & run. – Ciril Sep 28 '16 at 11:13
  • see this for your solution https://stackoverflow.com/questions/47887296/how-can-i-fix-this-error-in-android-adobe-sdk-tool –  Apr 09 '18 at 08:51

9 Answers9

55

You are getting NoClassDefFoundError & ClassNotFoundException

NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available at compile time.

FYI

You are using Eclipse. Android Studio is a far simpler way to develop for Android if you manage to get the hang of it. For developers who have been using Eclipse, migrating to Studio is a nightmare for them. Eclipse is dead (My personal opinion).

For your NoClassDefFoundError problem goto rebuild option under Project > Clean and then select the project you want to clean up .Then Restart your Eclipse and run again .

Solutions

Check your classpath contains that jar (AppCompat), if your classpath doesn't contain the jar then just add that class in your classpath.

You should Use Android Studio instead of Eclipse . Read

  1. Support Library Features

The Gradle build script dependency identifier for this library is as follows:

com.android.support:appcompat-v7:24.2.1

Then Clean-Rebuild-Restart IDE

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • 1
    Thanks for the comment. Finally solved including the correct appcompat library. Unfortunelly, I'm not capable to migrate all my projects to AndroidStudio at this moment. – The Matrix Oct 01 '16 at 18:44
  • 4
    @IntelliJAmiya hello I have the same problem from Android Studio, and I have already imported this library in both my main application and the aar applicaiton. – Libathos Jun 28 '17 at 10:50
16

In my case

  1. clean project
  2. invalidate and restart

it's work

Lonie
  • 275
  • 2
  • 12
5

Another ugly reason for this to be caused is if you're trying to attach a debugger with breakpoint on something that happens during Activity creation.

Rock_Artist
  • 555
  • 8
  • 14
  • For me it was a different error that is similar to this one, I had also appcompat class not found, but after migration to AndroidX and the problem was that my auto added appcompat dependency was too old. (version 1.0.0). When I updated to version 1.2.0 the problem was solved: ```implementation "androidx.appcompat:appcompat:1.2.0"``` – Vitali Pom Jan 17 '21 at 19:41
3

I added two classes in my java package and its working fine, keep both class as showing in below image:

enter image description here

AsyncTaskCompat.java

public class AsyncTaskCompat {

/**
 * Executes the task with the specified parameters, allowing multiple tasks to run in parallel
 * on a pool of threads managed by {@link android.os.AsyncTask}.
 *
 * @param task The {@link android.os.AsyncTask} to execute.
 * @param params The parameters of the task.
 * @return the instance of AsyncTask.
 */
public static <Params, Progress, Result> AsyncTask<Params, Progress, Result> executeParallel(
        AsyncTask<Params, Progress, Result> task, Params... params) {
    if (task == null) {
        throw new IllegalArgumentException("task can not be null");
    }

    if (Build.VERSION.SDK_INT >= 11) {
        // From API 11 onwards, we need to manually select the THREAD_POOL_EXECUTOR
        AsyncTaskCompatHoneycomb.executeParallel(task, params);
    } else {
        // Before API 11, all tasks were run in parallel
        task.execute(params);
    }

    return task;
}
}

AsyncTaskCompatHoneycomb.java

class AsyncTaskCompatHoneycomb {

static <Params, Progress, Result> void executeParallel(
        AsyncTask<Params, Progress, Result> task, Params... params) {
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
}
varotariya vajsi
  • 3,965
  • 37
  • 39
0

In my case the error was caused due to the use of the entire gms:play-services library. Some components of gms:play-services refer to versions other than explicitly specified by you.

Use only the required play-services which are required e.g: 'com.google.android.gms:play-services-analytics:10.2.0' instead of 'com.google.android.gms:play-services:10.2.0'.

Also see: All com.android.support libraries must use the exact same version specification

Good read: https://blog.mindorks.com/avoiding-conflicts-in-android-gradle-dependencies-28e4200ca235

Abhisek Mallick
  • 116
  • 2
  • 5
0
public class MApplication extends Application {

    @Override
    protected void attachBaseContext(Context paramContext) {
        super.attachBaseContext(paramContext);
        Helper.install(MApplication.this);
    }
}

Here we override the attachBaseContext() method to add the Helper.install(MApplication.this); line of code.

Note: Since some of SDK classes now need to be loaded before using, the loading process is done by Helper.install(). Developer needs to invoke this method before using any SDK functionality. Failing to do so will result in unexpected crashes. reference

Unless the app crashes with java.lang.NoClassDefFoundError: Failed resolution of:....

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
SaadurRehman
  • 622
  • 8
  • 20
0

Update implementation com.google.android.gms:play-services-maps in gradle to a newer version.

That worked for me.

Simson
  • 3,373
  • 2
  • 24
  • 38
MSilva
  • 151
  • 1
  • 6
0

I had a very similar issue, the problem was using an old (deprecated) package, more that 4 years without maintenance. Check your reciently added packages and check if they're compatible with you Android SDK.

Tincho825
  • 829
  • 1
  • 13
  • 15
0

In my case, just cleaning and rebuilding the project worked for me.

Abel Tilahun
  • 1,705
  • 1
  • 16
  • 25