I bump into the following error when upgrading compileSdkVersion/targetSdkVersion to 28 (from 27) while using
Fatal Exception: java.lang.NoClassDefFoundError Failed resolution of: Lorg/apache/http/ProtocolVersion;
NOTE: The error didn't occur on Android Pie (API 28) emulator / Android Lollipop (API 21) Phone / Android Oreo (API 26 Phone). It happened on a Android Pie (API 28) Phone.
Based on this source:
If you are using com.google.android.gms:play-services-maps:16.0.0 or below and your app is targeting API level 28 (Android 9.0) or above, you must include the following declaration within the
element of AndroidManifest.xml.
<?xml version="1.0" encoding="utf-8"?> <manifest ..> <uses-library android:name="org.apache.http.legacy" android:required="false" /> </manifest>
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.
NOTE: I opt to use
com.google.android.gms:play-services-maps:16.1.0 to solve problem instead.