java.lang.NoClassDefFoundError Failed resolution of: Lorg/apache/http/ProtocolVersion Android (9) Pie

 I built App on Android studio targetSdkVersion 28 which targets Android P. The APK can be build ,but when I used it on device with OS Android (9) Pie, it throws below crash and see below detailed crash log for more details.

ANDROID CRASHLYTICS ERROR LOG:
Fatal Exception: java.lang.NoClassDefFoundError
Failed resolution of: Lorg/apache/http/ProtocolVersion;
com.google.android.gms.common.data.zac.b (:com.google.android.gms.dynamite_adsdynamite@14799081@14.7.99 (100400-223214910):3)
com.google.android.gms.common.data.zab.a (:com.google.android.gms.dynamite_adsdynamite@14799081@14.7.99 (100400-223214910):3)
com.google.android.gms.common.internal.AccountAccessor.a (:com.google.android.gms.dynamite_adsdynamite@14799081@14.7.99 (100400-223214910):19)
com.google.android.gms.ads.internal.util.aq.a (:com.google.android.gms.dynamite_adsdynamite@14799081@14.7.99 (100400-223214910):15)
com.google.android.gms.common.api.internal.TaskUtil.a (:com.google.android.gms.dynamite_adsdynamite@14799081@14.7.99 (100400-223214910):19)
com.google.android.gms.common.api.internal.TaskUtil.run (:com.google.android.gms.dynamite_adsdynamite@14799081@14.7.99 (100400-223214910):8)
Caused by java.lang.ClassNotFoundException
Didn't find class "org.apache.http.ProtocolVersion" on path: DexPathList[[zip file "/data/user_de/0/com.google.android.gms/app_chimera/m/00000055/AdsDynamite.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/00000055/AdsDynamite.apk!/lib/arm64-v8a, /system/lib64]]
dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:169)
java.lang.ClassLoader.loadClass (ClassLoader.java:379)
com.bumptech.glide.load.engine.EngineKeyFactory.loadClass (:com.google.android.gms.dynamite_dynamiteloader@14799081@14.7.99 (100400-223214910):4)
java.lang.ClassLoader.loadClass (ClassLoader.java:312)
com.google.android.gms.common.data.zac.b (:com.google.android.gms.dynamite_adsdynamite@14799081@14.7.99 (100400-223214910):3)
com.google.android.gms.common.data.zab.a (:com.google.android.gms.dynamite_adsdynamite@14799081@14.7.99 (100400-223214910):3)
com.google.android.gms.common.internal.AccountAccessor.a (:com.google.android.gms.dynamite_adsdynamite@14799081@14.7.99 (100400-223214910):19)
com.google.android.gms.ads.internal.util.aq.a (:com.google.android.gms.dynamite_adsdynamite@14799081@14.7.99 (100400-223214910):15)
com.google.android.gms.common.api.internal.TaskUtil.a (:com.google.android.gms.dynamite_adsdynamite@14799081@14.7.99 (100400-223214910):19)
com.google.android.gms.common.api.internal.TaskUtil.run (:com.google.android.gms.dynamite_adsdynamite@14799081@14.7.99 (100400-223214910):8)

SOLUTION:
This link android-9.0-changes-28-->Apache HTTP client deprecation explains reason for adding the following to your AndroidManifest.xml:
<uses-library android:name="org.apache.http.legacy" android:required="false"/>

Similar errors : Need to specify requirement for Apache HTTP Legacy library
You can also face same error while using play-services-maps library. There are two solutions as below:

Solution 1: If you are working with com.google.android.gms:play-services-maps:16.0.0 or below then update the com.google.android.gms:play-services-maps library to the latest version. This is handled for you if you are using com.google.android.gms:play-services-maps:16.1.0 and is not necessary if your app is targeting a lower API level.
Or
Solution  2:  Include the below declaration within the <application> element of AndroidManifest.xml.
<uses-library
      android:name="org.apache.http.legacy"
      android:required="false" />
Refer the same included in the official docs: Specify requirement for Apache HTTP Legacy library
It's reported on issuetracker (Android bug tracker) :https://issuetracker.google.com/issues/79478779

More about Apache HTTP client deprecation:
With Android 6.0, we removed support for the Apache HTTP client. Beginning with Android 9, that library is removed from the bootclasspath and is not available to apps by default. To continue using the Apache HTTP client, apps that target Android 9 and above can add the following to their AndroidManifest.xml:
<uses-library android:name="org.apache.http.legacy" android:required="false">

Things to Note
 The android:required="false" attribute is required for apps that have a minimum SDK of 23 or lower, because on devices with API levels lower than 24, the org.apache.http.legacy library is not available. (On those devices, the Apache HTTP classes are available on the bootclasspath.) As an alternative to using the runtime Apache library, apps can bundle their own version of the org.apache.http library in their APK. If you do this, you must repackage the library (with a utility like Jar Jar) to avoid class compatibility issues with the classes provided in the runtime.

No comments:

Post a Comment

Popular Posts