Android Google maps java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion
Asked Answered
I

10

230

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@[email protected] (100408-196123505):3)
        at ek.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-196123505):4)
        at em.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-196123505):51)
        at com.google.maps.api.android.lib6.drd.ap.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-196123505):11)
        at dw.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-196123505):16)
        at dw.run(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (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@[email protected] (100408-196123505):25)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at el.b(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-196123505):3) 
        at ek.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-196123505):4) 
        at em.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-196123505):51) 
        at com.google.maps.api.android.lib6.drd.ap.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-196123505):11) 
        at dw.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-196123505):16) 
        at dw.run(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (100408-196123505):61) 
Idealize answered 10/6, 2018 at 10:35 Comment(7)
Already have multiDexEnabled true in defaultConfigIdealize
This issue occurs in Android P...works good on Android 5Idealize
Got this too, it happens only on the Android P beta 2.Inositol
I got this error, too. Using Android Studio and its emulator.Barman
The those seeing this error on API level 28 (Android 9.0), the Google Maps docs now describe the required manifest entry.Pilothouse
How to fix the same with Nativescript? #53325398Operand
I am using this on Samsung galaxy s8 & s9 and still not working. any other solution?Crockett
I
558

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

Inositol answered 11/6, 2018 at 9:18 Comment(8)
This solved the problem. Don't quite understand why this is required, though. MapsActivity I used seemed to be all regular..Barman
Android 9.0 is already released and Google still haven't fixed the maps library, neither documented that it requires this library. Very poor dev support.Expensive
@Expensive Google has documented it, see: developers.google.com/maps/documentation/android-sdk/…Inositol
Still, Apache HTTP client support has been removed since Android 6: https://developer.android.com/about/versions/marshmallow/android-6.0-changes#behavior-apache-http-clientRad
This also fixed java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/message/BasicNameValuePair; after I switched to AndroidX (and the subsequent 65K methods limit increase)Huberthuberto
does the legacy mode reduce map performance? with multiple markers and clusters?Downswing
This worked on react native as well, when app would crash when loading maps.Firman
This completely solved the problem for me in Android P version.Educated
G
43

This will resolve your crash. Apply this in manifest

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


<application/>
Gynandrous answered 19/9, 2018 at 11:27 Comment(6)
What is android:usesCleartextTraffic="true" good for? Other answers does not mention this line. So optional?Nicodemus
@TimoBähr it is not part of the answer. answer is what ham mentoned, Nicky's answer makes it clearer to show that you should insert this line within application tags.Edelsten
@TimoBähr the android:usesCleartextTraffic="true" is issue also that you will get later on, it is for security purposes.Lightening
@Lester.L If I declare android:usesCleartextTraffic=”true” this allows to communicate with cleartext http links - that is status quo. So as far as I understand only android:usesCleartextTraffic=”false” would make the app more "secure". Please correct me if I'm wrong.Nicodemus
I removed it. It has nothing to do with and answer itself and should possibly cause some security breach if someone copy&paste it.Orv
Ok but, when I press back button, this still appears in log -> 2019-06-11 23:11:26.279 8522-8522/com.example.myweatherapp E/SchedPolicy: set_timerslack_ns write failed: Operation not permittedCurst
C
19

Do one of the following solutions:

1- Update the play-services-maps library to latest version:

com.google.android.gms:play-services-maps:16.1.0

2- Or include the following declaration within the <application> element of AndroidManifest.xml.

<uses-library
      android:name="org.apache.http.legacy"
      android:required="false" />
Corium answered 12/2, 2019 at 16:29 Comment(1)
Both solutions are supported by this google doc: developers.google.com/maps/documentation/android-sdk/…Oligopoly
L
12

If your app is targeting API level 28 (Android 9.0) or above, you must include the following declaration within the <application> element of AndroidManifest.xml.

 <uses-library
       android:name="org.apache.http.legacy"
  android:required="false" />
Ludie answered 22/2, 2019 at 10:46 Comment(0)
K
5

If your app is targeting API level 28 (Android 9.0) or above, you must include the following declaration within the element of AndroidManifest.xml. see the behavioral changes of app targeting 28+ in the below link

https://developer.android.com/about/versions/pie/android-9.0-changes-28 https://developer.android.com/about/versions/pie/android-9.0-changes-28

Kiger answered 1/7, 2019 at 6:49 Comment(0)
A
2

If this happen in Android 8.0 or above then just put this line in your manifest application tag

<uses-library android:name="org.apache.http.legacy" android:required="false"/>
Astrix answered 18/7, 2019 at 10:42 Comment(0)
C
2

Here is the solution

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

Adding this line to your Menifest.xml inside <application> tag

for more info

Conker answered 26/11, 2019 at 7:47 Comment(0)
P
1

Set tis:

multiDexEnabled true

Like this:

android {
    compileSdkVersion 28
    defaultConfig {

        multiDexEnabled true

    }
    buildTypes {
        release {

        }
    }
}
Penner answered 27/7, 2019 at 5:38 Comment(0)
V
0

create an xml file res/xml/network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
      <base-config cleartextTrafficPermitted="true">
       <trust-anchors>
        <certificates src="system" />
       </trust-anchors>
      </base-config>
    </network-security-config>

And add 2 tags tag in your AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
 <manifest......>
  <application android:networkSecurityConfig="@xml/network_security_config">
   <activity..../> 
   ......
   ......
 <uses-library
        android:name="org.apache.http.legacy"
        android:required="false"/>
</application>

Also add useLibrary 'org.apache.http.legacy' in your app build gradle

defaultConfig {
        applicationId "com.ascorb"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 6
        versionName "1.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        useLibrary 'org.apache.http.legacy'
    }
Varletry answered 16/5, 2019 at 16:3 Comment(0)
M
0

Add permissions in Manifest file

`<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION."/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>`

and in part put this line of code

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

I had the same problem and It was fixed by this.

Maulstick answered 28/9, 2019 at 8:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.