I'm encountering this error when I use Android Studio to build my app. The APK is compiled, but when I attempt to run the app on Android P emulator, it will crash and throw the following error. Please see more details in the attachments:
java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion
This is my build.grade file. If anybody has a suggestion on what the problem could be, I would appreciate it. Many thanks.
android {
compileSdkVersion 'android-P'
buildToolsVersion '28-rc1'
useLibrary 'org.apache.http.legacy'
//for Lambda
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
defaultConfig {
applicationId "xxx.xxx.xxx"
minSdkVersion 17
targetSdkVersion 27
versionCode xxxx
versionName "Vx.x.x"
multiDexEnabled true
//other setting required
ndk {
abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a', 'x86', 'x86_64', 'mips', 'mips64'
}
Update: This is no longer a bug or a workaround, it is required if your app targets API Level 28 (Android 9.0) or above and uses the Google Maps SDK for Android 16.0.0 or below (or if your app uses the Apache HTTP Legacy library). It is now included in the official docs. The public issue has been closed as intended behavior.
This is a bug on the Google Play Services side, until it's fixed, you should be able to workaround by adding this to your AndroidManifest.xml
inside the <application>
tag:
<uses-library android:name="org.apache.http.legacy" android:required="false" />