当我使用Android Studio构建我的应用程序时,我遇到了这个错误。APK被编译,但当我试图在Android P模拟器上运行应用程序时,它会崩溃并抛出以下错误。详情请见附件:

java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion

这是我的身材。级文件。如果有人对问题有什么建议,我将不胜感激。多谢。

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漏洞追踪器https://issuetracker.google.com/issues/79478779上也有报道

更新:这不再是一个错误或解决方案,如果你的应用程序目标API级别28 (Android 9.0)或以上,并使用谷歌地图SDK for Android 16.0.0或以下(或如果你的应用程序使用Apache HTTP Legacy库),这是必需的。它现在被包含在官方文档中。公开的问题已被关闭作为有意的行为。

这是谷歌播放服务端的一个错误,直到它被修复,你应该能够通过将此添加到<application>标签内的AndroidManifest.xml来解决:

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

这个链接android-9.0-changes-28——>Apache HTTP客户端弃用解释了在你的AndroidManifest.xml中添加以下内容的原因:

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

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

做以下任何一件事:

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

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

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

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

如果你正在使用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级别,这是不必要的。

为了在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>

还可以添加useLibrary ` org.apache.http。遗留'在你的应用程序构建gradle

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'
}

根据这个SO的回答,它是由于AWS SDK的一个错误,该错误似乎在SDK的2.6.30版本中得到了解决,因此将版本更新到更新的版本可以帮助您解决这个问题。

如果你使用安卓9.0的遗留jar比你必须使用。 在你的mainfest文件里。

< uses-library android: name = " org.apache.http。遗产”android:要求= " false " / >

在react本机,我有错误不显示地图和关闭应用程序,运行adb logcat和显示错误在控制台:

java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion

通过在androidManifest.xml中添加来修复它

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

如果你正在使用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" />

查看这个链接- https://developers.google.com/maps/documentation/android-sdk/config#specify_requirement_for_apache_http_legacy_library

在你的AndroidManifest.xml中添加这两行。

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

请看下面的代码

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher"
        android:supportsRtl="true"
        android:usesCleartextTraffic="true"
        android:theme="@style/AppTheme"
        tools:ignore="AllowBackup,GoogleAppIndexingWarning">
        <activity android:name=".activity.SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

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

这可能是迟到的回答。但是,我希望这能节省一些人的时间:

如果你正在使用com.google.android.gms:play-services-maps:16.0.0或以下,并且你的应用程序是API级别28 (Android 9.0)或以上,你必须在AndroidManifest.xml的元素中包含以下声明

<application
        ...
        ...
        android:usesCleartextTraffic="true"
        android:requestLegacyExternalStorage="true">

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

</application>

注意:android:requestLegacyExternalStorage="true", android 10+访问存储R/W

Android 6.0在Android manifest的application元素下引入了useCleartextTraffic属性。Android P的默认值是false。将此设置为true表示应用程序打算使用清除网络流量。

如果你的应用程序在Android 10设备上运行时选择退出作用域存储,建议你在应用程序的清单文件中继续将requestLegacyExternalStorage设置为true。这样,你的应用程序就可以在运行Android 10的设备上继续正常运行