Olson CloudWorks 🚀

Android Google maps javalangNoClassDefFoundError Failed resolution of LorgapachehttpProtocolVersion

September 19, 2026

Android Google maps javalangNoClassDefFoundError Failed resolution of LorgapachehttpProtocolVersion

Encountering the java.lang.NoClassDefFoundError when working with Android Google Maps can be a frustrating experience, especially when the error message points to Lorg/apache/http/ProtocolVersion. This error typically arises when your Android application, which utilizes Google Maps, is missing a critical dependency or is misconfigured in terms of its build path. This specific issue indicates that the Apache HTTP client library, which was once a standard part of the Android SDK, is no longer available by default in newer Android versions (API level 23 and above). Understanding the root cause and implementing the correct solution is crucial for a smooth development process. We’ll delve into the reasons behind this error and provide step-by-step solutions to resolve it effectively, ensuring your mapping application runs flawlessly. This comprehensive guide aims to equip you with the knowledge to tackle this common Android development hurdle.

Understanding the java.lang.NoClassDefFoundError with Android Google Maps

The java.lang.NoClassDefFoundError is a runtime error in Java that occurs when the Java Virtual Machine (JVM) or, in this case, the Dalvik Virtual Machine (DVM) or Android Runtime (ART), cannot find a class definition that was available at compile time. When dealing with Android Google Maps and encountering this error specifically related to Lorg/apache/http/ProtocolVersion, it signals that the Apache HTTP client library, which your code relies on, is absent during runtime. This absence is because Google deprecated the Apache HTTP client in Android 6.0 (API level 23) and removed it entirely in Android 9.0 (API level 28). If your app targets a newer API level but still uses code dependent on this library, you’ll inevitably face this error.

To further clarify, the error doesn’t mean the class is completely missing from the system. It simply means the class loader cannot find it at runtime. This could be due to various reasons, such as the library not being properly included in your project’s dependencies, an incorrect build configuration, or conflicts with other libraries. The Apache HTTP client library provides functionalities for making HTTP requests, a common task when interacting with web services, including those that provide map data and services. Ignoring this error can lead to application crashes and a poor user experience, so addressing it promptly is essential. For more information on the Apache HTTP client deprecation, refer to the official Android documentation. Android 6.0 Changes

Solutions to Resolve the NoClassDefFoundError

Fortunately, resolving the java.lang.NoClassDefFoundError related to the Apache HTTP client in your Android Google Maps project is relatively straightforward. There are two primary approaches you can take: re-enable the Apache HTTP client in your project or migrate your code to use the java.net.HttpURLConnection or OkHttp library. The recommended approach is to migrate your code, as the Apache HTTP client is deprecated and may be removed entirely in future Android versions. However, if you need a quick fix, re-enabling the client can be a temporary solution.

Re-enabling the Apache HTTP client involves adding the following to your build.gradle file within the android block: useLibrary 'org.apache.http.legacy'. This tells the Android build system to include the legacy Apache HTTP client library in your app’s build. However, be aware that this is a temporary workaround. Migrating to a supported HTTP client library is the more sustainable approach. The featured snippet optimized paragraph below further details how to re-enable the Apache HTTP client.

Featured Snippet: To quickly resolve the java.lang.NoClassDefFoundError for Lorg/apache/http/ProtocolVersion in your Android project, add useLibrary 'org.apache.http.legacy' inside the android block of your build.gradle file. This re-enables the legacy Apache HTTP client library, allowing your application to find the necessary classes at runtime. Remember to sync your Gradle files after making this change to apply the updates. This is a temporary fix, and migrating to a supported HTTP client like HttpURLConnection or OkHttp is highly recommended for long-term stability and compatibility.

Step-by-Step Guide to Re-enabling Apache HTTP Client

Here’s a step-by-step guide on how to re-enable the Apache HTTP client in your Android project:

  1. Open your project in Android Studio.
  2. Locate the build.gradle file for your app module (usually app/build.gradle).
  3. Open the build.gradle file in a text editor.
  4. Inside the android block, add the line: useLibrary 'org.apache.http.legacy'.
  5. Sync your Gradle files by clicking “Sync Now” in the banner that appears or by selecting “Build” > “Sync Project with Gradle Files” from the menu.
  6. Clean and rebuild your project (Build > Clean Project, then Build > Rebuild Project).

After following these steps, the java.lang.NoClassDefFoundError should be resolved. However, remember that this is a temporary solution. You should still plan to migrate your code to use a supported HTTP client library for long-term maintainability and to avoid potential issues in future Android versions. As per Stack Overflow, many developers have used this approach successfully. Stack Overflow Discussion

Migrating to HttpURLConnection or OkHttp

The recommended long-term solution is to migrate your code from using the deprecated Apache HTTP client to either java.net.HttpURLConnection, which is part of the standard Java library, or a more modern HTTP client library like OkHttp. OkHttp is a popular and efficient HTTP client that is easy to use and provides excellent performance. It’s developed by Square and is widely used in Android development.

Migrating to HttpURLConnection involves replacing your existing Apache HTTP client code with equivalent code using HttpURLConnection. This typically involves creating a URL object, opening a connection using openConnection(), setting request headers, writing data to the connection (for POST requests), and reading the response. Migrating to OkHttp involves adding the OkHttp dependency to your build.gradle file and then using the OkHttp API to make HTTP requests. Here’s how to add the OkHttp dependency:

dependencies { implementation("com.squareup.okhttp3:okhttp:4.10.0") // Replace with the latest version } 

After adding the dependency, you can start using OkHttp in your code. OkHttp provides a more fluent and easier-to-use API compared to HttpURLConnection. Here are some key advantages of using OkHttp:

  • It supports HTTP/2 and HTTP/3, enabling faster and more efficient network communication.
  • It automatically handles connection pooling, reducing latency and improving performance.
  • It provides built-in support for GZIP compression, reducing the size of HTTP responses.
Infographic here
Best Practices for Avoiding NoClassDefFoundError in Android Google Maps Development -----------------------------------------------------------------------------------

To minimize the risk of encountering java.lang.NoClassDefFoundError and similar issues in your Android Google Maps development, follow these best practices:

  • Keep your dependencies up to date: Regularly update your project’s dependencies to the latest versions to ensure compatibility and benefit from bug fixes and performance improvements.
  • Use a dependency management tool: Use Gradle or Maven to manage your project’s dependencies. This makes it easier to add, update, and remove dependencies, and it helps to avoid dependency conflicts.
  • Be aware of API deprecations: Stay informed about API deprecations and removals in the Android SDK and migrate your code to use supported APIs as soon as possible.

Furthermore, thoroughly test your application on different Android versions and devices to identify and resolve any compatibility issues early in the development process. Use tools like Android Lint to detect potential problems in your code, including usage of deprecated APIs. According to a Google Developers blog post, proactive dependency management and testing are crucial for stable app development. Google Developers Blog

FAQ: java.lang.NoClassDefFoundError and Android Google Maps

Why am I getting java.lang.NoClassDefFoundError: Lorg/apache/http/ProtocolVersion?
This error occurs because the Apache HTTP client library, which was once included in the Android SDK, has been deprecated and removed in newer Android versions. Your code is likely still referencing this library.
Is re-enabling the Apache HTTP client a permanent solution?
No, re-enabling the Apache HTTP client is a temporary workaround. It's recommended to migrate your code to use a supported HTTP client like HttpURLConnection or OkHttp for long-term stability.
How do I migrate to OkHttp?
First, add the OkHttp dependency to your build.gradle file. Then, replace your existing Apache HTTP client code with equivalent code using the OkHttp API. Refer to the OkHttp documentation for detailed instructions.
Addressing the `java.lang.NoClassDefFoundError` involving `Lorg/apache/http/ProtocolVersion` in your **Android Google Maps** project requires understanding the changes in the Android SDK and adopting a proactive approach to dependency management. While re-enabling the Apache HTTP client offers a quick fix, migrating to a supported HTTP client like OkHttp ensures long-term compatibility and stability. By following the best practices outlined above, you can minimize the risk of encountering this and other similar issues, creating a smoother and more reliable development experience.

If you’ve been struggling with this error, take the steps outlined above to either temporarily re-enable the legacy library or, more importantly, begin the process of migrating to a modern HTTP client. Don’t let this error hold you back from building amazing mapping applications! Consider exploring other common Android development errors and their solutions to further enhance your skills. Learn more about troubleshooting Android issues here.

Question & Answer :
I am using Google maps Android SDK 11.6.2(Also tried 15.0.1),but I get following crash before map shows. Already checked API key in manifest,it is available, but still this issue occurs. I am having targetSDk version as 28.Is it causes this issue.

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion; at el.b(:com.google.android.gms.dynamite_mapsdynamite@<a class="__cf_email__" data-cfemail="5061626864686066631061627e687e6468" href="/cdn-cgi/l/email-protection">[email protected]</a> (100408-196123505):3) at ek.a(:com.google.android.gms.dynamite_mapsdynamite@<a class="__cf_email__" data-cfemail="85b4b7bdb1bdb5b3b6c5b4b7abbdabb1bd" href="/cdn-cgi/l/email-protection">[email protected]</a> (100408-196123505):4) at em.a(:com.google.android.gms.dynamite_mapsdynamite@<a class="__cf_email__" data-cfemail="2c1d1e1418141c1a1f6c1d1e0214021814" href="/cdn-cgi/l/email-protection">[email protected]</a> (100408-196123505):51) at com.google.maps.api.android.lib6.drd.ap.a(:com.google.android.gms.dynamite_mapsdynamite@<a class="__cf_email__" data-cfemail="5061626864686066631061627e687e6468" href="/cdn-cgi/l/email-protection">[email protected]</a> (100408-196123505):11) at dw.a(:com.google.android.gms.dynamite_mapsdynamite@<a class="__cf_email__" data-cfemail="3001020804080006037001021e081e0408" href="/cdn-cgi/l/email-protection">[email protected]</a> (100408-196123505):16) at dw.run(:com.google.android.gms.dynamite_mapsdynamite@<a class="__cf_email__" data-cfemail="2716151f131f171114671615091f09131f" href="/cdn-cgi/l/email-protection">[email protected]</a> (100408-196123505):61) Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.ProtocolVersion" on path: DexPathList[[zip file "/system/priv-app/PrebuiltGmsCorePi/app_chimera/m/MapsDynamite.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/00000036/MapsDynamite.apk!/lib/armeabi-v7a, /data/user_de/0/com.google.android.gms/app_chimera/m/00000036/MapsDynamite.apk!/lib/armeabi, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:126) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at ad.loadClass(:com.google.android.gms.dynamite_dynamiteloader@<a class="__cf_email__" data-cfemail="1120232925292127225120233f293f2529" href="/cdn-cgi/l/email-protection">[email protected]</a> (100408-196123505):25) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at el.b(:com.google.android.gms.dynamite_mapsdynamite@<a class="__cf_email__" data-cfemail="9faeada7aba7afa9acdfaeadb1a7b1aba7" href="/cdn-cgi/l/email-protection">[email protected]</a> (100408-196123505):3)  at ek.a(:com.google.android.gms.dynamite_mapsdynamite@<a class="__cf_email__" data-cfemail="90a1a2a8a4a8a0a6a3d0a1a2bea8bea4a8" href="/cdn-cgi/l/email-protection">[email protected]</a> (100408-196123505):4)  at em.a(:com.google.android.gms.dynamite_mapsdynamite@<a class="__cf_email__" data-cfemail="3d0c0f0509050d0b0e7d0c0f1305130905" href="/cdn-cgi/l/email-protection">[email protected]</a> (100408-196123505):51)  at com.google.maps.api.android.lib6.drd.ap.a(:com.google.android.gms.dynamite_mapsdynamite@<a class="__cf_email__" data-cfemail="6c5d5e5458545c5a5f2c5d5e4254425854" href="/cdn-cgi/l/email-protection">[email protected]</a> (100408-196123505):11)  at dw.a(:com.google.android.gms.dynamite_mapsdynamite@<a class="__cf_email__" data-cfemail="a697949e929e969095e69794889e88929e" href="/cdn-cgi/l/email-protection">[email protected]</a> (100408-196123505):16)  at dw.run(:com.google.android.gms.dynamite_mapsdynamite@<a class="__cf_email__" data-cfemail="f9c8cbc1cdc1c9cfcab9c8cbd7c1d7cdc1" href="/cdn-cgi/l/email-protection">[email protected]</a> (100408-196123505):61)  

Put this in the Manifest <application> tag:

<uses-library android:name="org.apache.http.legacy" android:required="false"/> 

More info: https://issuetracker.google.com/issues/79478779