Android:ClassNotFoundException:Didn't find class "org.apache.http.util.Args"

warning: 这篇文章距离上次修改已过710天,其中的内容可能已经有所变动。

原文链接:https://blog.csdn.net/qq_33721320/article/details/86620524

在 Android 6.0 中,我们取消了对 Apache HTTP 客户端的支持。 从 Android 9 开始,默认情况下该内容库已从 bootclasspath 中移除且不可用于应用。

要继续使用 Apache HTTP 客户端,以 Android 9 及更高版本为目标的应用可以向其 AndroidManifest.xml的###application节点下 添加以下内容:
<uses-library
    android:name="org.apache.http.legacy"
    android:required="false" />

在application下面添加 uses-library。即可

        <application
            android:name=".MyApp"
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:usesCleartextTraffic="true"
            android:theme="@style/AppTheme">
 
            <uses-library
                android:name="org.apache.http.legacy"
                android:required="false" />
 
            <activity
                android:name=".activity.SplashActivity"
                android:exported="true"
                android:screenOrientation="portrait"
                android:theme="@style/Splash">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
 
                    <category android:name="android.intent.category.LAUNCHER" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
 
        </application>
<!--android:usesCleartextTraffic="true"主要是适配9.0的Http网络请求。-->

注:拥有最低 SDK 版本 23 或更低版本的应用需要 android:required="false" 属性,因为在 API 级别低于 24 的设备上,org.apache.http.legacy 库不可用。 (在这些设备上,Apache HTTP 类在 bootclasspath 中提供。)
作为使用运行时 Apache 库的替代,应用可以在其 APK 中绑定自己的 org.apache.http 库版本。 如果进行此操作,您必须将该库重新打包(使用一个类似 Jar Jar 的实用程序)以避免运行时中提供的类存在类兼容性问题。

none
最后修改于:2022年05月10日 01:07

添加新评论