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@12848063@12.8.48 (100408-196123505):3)
        at ek.a(:com.google.android.gms.dynamite_mapsdynamite@12848063@12.8.48 (100408-196123505):4)
        at em.a(:com.google.android.gms.dynamite_mapsdynamite@12848063@12.8.48 (100408-196123505):51)
        at com.google.maps.api.android.lib6.drd.ap.a(:com.google.android.gms.dynamite_mapsdynamite@12848063@12.8.48 (100408-196123505):11)
        at dw.a(:com.google.android.gms.dynamite_mapsdynamite@12848063@12.8.48 (100408-196123505):16)
        at dw.run(:com.google.android.gms.dynamite_mapsdynamite@12848063@12.8.48 (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@12848063@12.8.48 (100408-196123505):25)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at el.b(:com.google.android.gms.dynamite_mapsdynamite@12848063@12.8.48 (100408-196123505):3) 
        at ek.a(:com.google.android.gms.dynamite_mapsdynamite@12848063@12.8.48 (100408-196123505):4) 
        at em.a(:com.google.android.gms.dynamite_mapsdynamite@12848063@12.8.48 (100408-196123505):51) 
        at com.google.maps.api.android.lib6.drd.ap.a(:com.google.android.gms.dynamite_mapsdynamite@12848063@12.8.48 (100408-196123505):11) 
        at dw.a(:com.google.android.gms.dynamite_mapsdynamite@12848063@12.8.48 (100408-196123505):16) 
        at dw.run(:com.google.android.gms.dynamite_mapsdynamite@12848063@12.8.48 (100408-196123505):61) 
Ramprasad
  • 7,981
  • 20
  • 74
  • 135
  • Already have multiDexEnabled true in defaultConfig – Ramprasad Jun 10 '18 at 10:39
  • 6
    This issue occurs in Android P...works good on Android 5 – Ramprasad Jun 10 '18 at 11:08
  • 1
    Got this too, it happens only on the Android P beta 2. – jeff Jun 11 '18 at 08:58
  • I got this error, too. Using Android Studio and its emulator. – frankliuao Jul 22 '18 at 15:42
  • 16
    The those seeing this error on API level 28 (Android 9.0), the Google Maps docs now describe [the required manifest entry](https://developers.google.com/maps/documentation/android-sdk/config#specify_requirement_for_apache_http_legacy_library). – Bob Snyder Aug 15 '18 at 20:16
  • How to fix the same with Nativescript? https://stackoverflow.com/questions/53324898/nativescript-google-maps-java-lang-noclassdeffounderror-failed-resolution-of-l – dev dev Nov 15 '18 at 17:28
  • I am using this on Samsung galaxy s8 & s9 and still not working. any other solution? – Pxaml Apr 03 '19 at 20:55

10 Answers10

554

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

Lokesh
  • 3,247
  • 2
  • 33
  • 62
jeff
  • 6,299
  • 1
  • 15
  • 18
  • 9
    This solved the problem. Don't quite understand why this is required, though. MapsActivity I used seemed to be all regular.. – frankliuao Jul 22 '18 at 15:46
  • 8
    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. – headsvk Oct 01 '18 at 11:18
  • 42
    @headsvk Google has documented it, see: https://developers.google.com/maps/documentation/android-sdk/config#specify_requirement_for_apache_http_legacy_library – jeff Oct 01 '18 at 11:25
  • 1
    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-client](https://developer.android.com/about/versions/marshmallow/android-6.0-changes#behavior-apache-http-client) – wamfous Jan 09 '19 at 08:26
  • 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) – Someone Somewhere May 09 '19 at 16:29
  • does the legacy mode reduce map performance? with multiple markers and clusters? – Daniel Givoni Jul 03 '19 at 13:45
  • This worked on react native as well, when app would crash when loading maps. – Thomas Uchiha Jul 29 '19 at 22:03
  • This completely solved the problem for me in Android P version. – Alvaro Lazaro Feb 14 '20 at 06:38
43

This will resolve your crash. Apply this in manifest

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


<application/>
JerabekJakub
  • 5,268
  • 4
  • 26
  • 33
Nicky
  • 885
  • 9
  • 21
  • 1
    What is `android:usesCleartextTraffic="true"` good for? Other answers does not mention this line. So optional? – Timo Bähr Dec 18 '18 at 18:57
  • 1
    @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. – Emil Dec 20 '18 at 15:51
  • @TimoBähr the `android:usesCleartextTraffic="true"` is issue also that you will get later on, it is for security purposes. – Lester L. Jan 04 '19 at 07:41
  • @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. – Timo Bähr Jan 04 '19 at 08:01
  • 1
    I removed it. It has nothing to do with and answer itself and should possibly cause some security breach if someone copy&paste it. – JerabekJakub Jan 14 '19 at 06:38
  • 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 permitted – Sanjit Prasad Jun 11 '19 at 17:42
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" />
Darush
  • 11,403
  • 9
  • 62
  • 60
  • Both solutions are supported by this google doc: https://developers.google.com/maps/documentation/android-sdk/config#specify_requirement_for_apache_http_legacy_library –  Jun 24 '19 at 13:45
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" />
Suman
  • 1,307
  • 15
  • 32
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

creativecoder
  • 1,470
  • 1
  • 14
  • 23
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"/>
Abdul Basit Rishi
  • 2,268
  • 24
  • 30
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

umi
  • 157
  • 1
  • 6
1

Set tis:

multiDexEnabled true

Like this:

android {
    compileSdkVersion 28
    defaultConfig {

        multiDexEnabled true

    }
    buildTypes {
        release {

        }
    }
}
reza_khalafi
  • 6,230
  • 7
  • 56
  • 82
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'
    }
Sudhir Singh
  • 817
  • 11
  • 16
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.

Mina Roger
  • 109
  • 4