App crashes when running maps activity

2019-02-17 17:25发布

问题:

My projects Map activity is not working
I just pasted the api key in place google_maps_api.xml and clicked run

Logcat:

E/AndroidRuntime: FATAL EXCEPTION: Thread-5 Process: com.example.appmy.lofind, PID: 10901 java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion; at el.b(:com.google.android.gms.dynamite_mapsdynamite@12848026@12.8.48 (040700-196123505):3) at ek.a(:com.google.android.gms.dynamite_mapsdynamite@12848026@12.8.48 (040700-196123505):4) at em.a(:com.google.android.gms.dynamite_mapsdynamite@12848026@12.8.48 (040700-196123505):51) at com.google.maps.api.android.lib6.drd.ap.a(:com.google.android.gms.dynamite_mapsdynamite@12848026@12.8.48 (040700-196123505):11) at dw.a(:com.google.android.gms.dynamite_mapsdynamite@12848026@12.8.48 (040700-196123505):16) at dw.run(:com.google.android.gms.dynamite_mapsdynamite@12848026@12.8.48 (040700-196123505):61) Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.ProtocolVersion" on path: DexPathList[[zip file "/system/priv-app/PrebuiltGmsCore/app_chimera/m/MapsDynamite.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/00000006/MapsDynamite.apk!/lib/x86, /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@12848026@12.8.48 (040700-196123505):25) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at el.b(:com.google.android.gms.dynamite_mapsdynamite@12848026@12.8.48 (040700-196123505):3)  at ek.a(:com.google.android.gms.dynamite_mapsdynamite@12848026@12.8.48 (040700-196123505):4)  at em.a(:com.google.android.gms.dynamite_mapsdynamite@12848026@12.8.48 (040700-196123505):51)  at com.google.maps.api.android.lib6.drd.ap.a(:com.google.android.gms.dynamite_mapsdynamite@12848026@12.8.48 (040700-196123505):11)  at dw.a(:com.google.android.gms.dynamite_mapsdynamite@12848026@12.8.48 (040700-196123505):16)  at dw.run(:com.google.android.gms.dynamite_mapsdynamite@12848026@12.8.48 (040700-196123505):61)  E/SchedPolicy: set_timerslack_ns write failed: Operation not permitted

回答1:

The same problem here when using target SDK 28. Reverting to SDK 27 solved the problem.


Don't revert your target SDK.

Better use this solution https://stackoverflow.com/a/50944537/5710605



回答2:

I've found another solution at Android Google maps java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion

Just add this in your manifest:

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

Update:

Starting from Google Maps SDK version 16.1.0 you can skip adding the solution above as the tag has been added to the AndroidManifest of the maps library.

https://developers.google.com/maps/documentation/android-sdk/releases#2019-02-06

Added the following declaration to the AndroidManifest.xml to support the Apache HTTP client on Android P and above. After updating to com.google.android.gms:play-services-maps:16.1.0 you can remove this line from your own AndroidManifest.xml. (Issue 117591497)

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