Android Google maps java.lang.NoClassDefFoundError Failed resolution of Lorg/apache/http/ProtocolVersion
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Android developers often encounter a complex ecosystem that demands continuous adaptation to libraries and APIs. One such common issue is the `java.lang.NoClassDefFoundError` related to an older Apache HTTP client class `ProtocolVersion`. When integrating Google Maps or similar libraries on Android, it isn't uncommon to encounter this error.
Understanding `java.lang.NoClassDefFoundError`
The `java.lang.NoClassDefFoundError` exception indicates the application attempted to access a class that is not present in the application’s classpath at runtime. This is distinct from `ClassNotFoundException`, which occurs when a class is not found during the class loading process. In this case, the error implies a dependency issue that surfaces on invoking certain methods.
The Problem: `Lorg/apache/http/ProtocolVersion`
This specific class, `org.apache.http.ProtocolVersion`, is part of the Apache HTTP client library, which has been deprecated in Android's API level 23 and removed in level 28. The problem often surfaces when an application, directly or indirectly, invokes a function relying on this class but was not adjusted to the updated HTTP client usage patterns.
When It Arises
The error typically arises in the context of:
- Using libraries not updated for API level 23 or later: Libraries such as certain old versions of Google Maps SDK might still rely on or include references to Apache HTTP client classes.
- Migrating to API level 23+ without proper refactoring: Projects, particularly older ones, may overlook the necessary changes when targeting newer API levels.
- Custom code inadvertently using deprecated methods: Direct or indirect calls from custom implementations in the project.
Technical Background
Android transitioned to the `HttpURLConnection` class for handling HTTP connections, deemphasizing Apache HTTP client. Here's what you need to understand about its operation and changes:
- Apache vs. HttpURLConnection: The main distinction between the two libraries is that `HttpURLConnection` is ingrained within the Android SDK, whereas Apache exists as an external library, now deprecated.
- Gradle Dependencies: If you are dependent on a library that has not evolved past Apache HTTP, you will likely see this error unless mitigations are enacted.
How To Resolve
- Verify Your Dependencies: Utilize the Gradle Dependency Insight to inspect which libraries are introducing deprecated references.
Related reading
- Android map v2 zoom to show all the markers
- AngularJS Avoid calling same REST service twice before response is received
- AngularJS http ajax request is not asynchronous and causes page to hang
- Apache Config Websockets Proxy WSS request to WS backend
- Android Gradle Apache HttpClient does not exist?
- Android Gradle plugin 0.7.0 duplicate files during packaging of APK
- Android high quality image resizing / scaling
- Android How can I get the current foreground activity from a service?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.