3

Getting this error on JellyBean:

01-11 18:26:52.030: E/AndroidRuntime(16517): FATAL EXCEPTION: main
01-11 18:26:52.030: E/AndroidRuntime(16517): java.lang.NoClassDefFoundError: android.support.v4.util.ArrayMap
01-11 18:26:52.030: E/AndroidRuntime(16517):    at com.google.android.gms.common.api.GoogleApiClient$Builder.<init>(Unknown Source)
01-11 18:26:52.030: E/AndroidRuntime(16517):    at com.example.services.LocationService.initGoogleApiClient(LocationService.java:82)
01-11 18:26:52.030: E/AndroidRuntime(16517):    at com.example.services.LocationService.start(LocationService.java:73)

The project still uses Eclipse.

There are two questions about this problem, resolved in ways that do not help my case:

Crash with Android 4.1 with ArrayMap - I cannot change the Google code that crashes in my case

Android error - Caused by: java.lang.NoClassDefFoundError: android.support.v4.util.SparseArrayCompat - It is already ticked, but doesnt work

Community
  • 1
  • 1
Kaloyan Roussev
  • 14,515
  • 21
  • 98
  • 180
  • 2
    Make sure that you are using the latest `support-v4` library. Note that with Eclipse, downloading the latest library is insufficient; you need to actually replace your existing copy that Eclipse is using with a fresh copy of the library. – CommonsWare Jan 11 '16 at 16:32
  • Thank you very much! This is the right answer. If you post it I will accept it. I had 4 library projects each having a version of the support-v4. Deleted it from all of them, pasted the latest support-v4 in the main project, linked all projects to it and got the project running again – Kaloyan Roussev Jan 11 '16 at 16:39

2 Answers2

6

Frequently, a problem regarding a missing android.support class means that you have an older version of the affected library, one from before the class in question was added. Unfortunately, the JavaDocs do a poor job of indicating which version of the support libraries added newer classes.

If you are using Android Studio, make sure that your support- dependencies are fairly recent, and that your compileSdkVersion matches the major version number of the dependency.

If you are using Eclipse, you will have to not only download the latest libraries from the SDK Manager, but then remove the old library from your Eclipse project and add in an up-to-date copy of the library from your SDK installation.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

It happened to me when I added google-play-services_lib library project (from ASDK extras) to my IDE (IntellyJ Idea), per official google docs. The library project references google-play-services.jar which in turn needs support-v4 jar, but this dependency is not included into google-play-services_lib.

In the logcat there were other warning about missing support-v4 classes too.

Adding support-v4 jar manually to main application project solved the issue.

Mixaz
  • 4,068
  • 1
  • 29
  • 55