java.lang.NoClassDefFoundError:解析失败:Lorg / apache / http / ProtocolVersion

问题描述 投票:186回答:6

当我使用Android Studio 3.1构建Android P的应用程序时,我遇到了这样的错误,可以制作apk,但是当我在Android P模拟器上使用它时,它会崩溃并抛出以下信息,更多细节请参见图片。

java.lang.NoClassDefFoundError:解析失败:Lorg / apache / http / ProtocolVersion

App模块下的build.gradle的一部分在下面,有人见过这个吗?并给出一些建议?非常感谢。

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'

        }
android google-maps gradle apache-httpcomponents android-9.0-pie
6个回答
620
投票

更新:这不再是错误或变通方法,如果您的应用针对API级别28(Android 9.0)或更高版本并使用适用于Android 16.0.0或更低版本的Google Maps SDK(或者您的应用使用Apache HTTP),则需要遗产图书馆)。它现在包含在official docs中。公共问题一直是closed的预期行为。

这是Google Play服务方面的bug,在修复之前,您应该可以通过将其添加到AndroidManifest.xml标记内的<application>来解决此问题:

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

36
投票

此链接android-9.0-changes-28-->Apache HTTP client deprecation解释了将以下内容添加到AndroidManifest.xml的原因:

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

在Android 6.0中,我们删除了对Apache HTTP客户端的支持。从Android 9开始,该库将从bootclasspath中删除,默认情况下不可用于应用程序。


19
投票

请执行以下任何操作:

1-将play-services-maps库更新到最新版本:

com.google.android.gms:play-services-maps:16.1.0

2-或者在<application>AndroidManifest.xml元素中包含以下声明。

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

14
投票

它还报告了Android bug跟踪器:https://issuetracker.google.com/issues/79478779


8
投票

在Android 9.0中运行org.apache.http.legacy完全创建一个xml文件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>

并在AndroidManifest.xml中添加2个标签标签

android:networkSecurityConfig =“@ xml / network_security_config”android:name =“org.apache.http.legacy”

<?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>

还要在app build gradle中添加useLibrary 'org.apache.http.legacy'

android {
compileSdkVersion 28
defaultConfig {
    applicationId "your application id"
    minSdkVersion 15
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    useLibrary 'org.apache.http.legacy'
}

3
投票

如果您使用的是com.google.android.gms:play-services-maps:16.0.0或更低版本且您的应用定位到API级别28(Android 9.0)或更高版本,则必须在AndroidManifest的元素中包含以下声明。 XML。

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

如果您使用的是com.google.android.gms:play-services-maps:16.1.0,则可以使用此功能,如果您的应用定位到较低的API级别,则无需这样做。


0
投票

根据this SO answer,它出现的原因是AWS SDK错误似乎已经解决了in version 2.6.30 of the SDK,因此将版本更新为更新版本可以帮助您解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.