219
votes

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) 
10
Already have multiDexEnabled true in defaultConfig - Ramprasad
This issue occurs in Android P...works good on Android 5 - Ramprasad
Got this too, it happens only on the Android P beta 2. - ham
I got this error, too. Using Android Studio and its emulator. - frankliuao
The those seeing this error on API level 28 (Android 9.0), the Google Maps docs now describe the required manifest entry. - Bob Snyder

10 Answers

530
votes

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

42
votes

This will resolve your crash. Apply this in manifest

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


<application/>
18
votes

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" />
11
votes

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" />
5
votes

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

2
votes

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"/>
1
votes

Set tis:

multiDexEnabled true

Like this:

android {
    compileSdkVersion 28
    defaultConfig {

        multiDexEnabled true

    }
    buildTypes {
        release {

        }
    }
}
0
votes

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.

0
votes

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

0
votes

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'
    }