java.lang.NoClassDefFoundError: Failed resolution of: Lorg\apache\http\conn\scheme\SchemeRegistry
描述
线上unity3d的项目,玩家反馈在android9机器上闪退。
logcat跑了一下,报错如题。
原因
Apache HTTP 客户端弃用
从 Android 9 开始,默认情况下该内容库已从 bootclasspath 中移除且不可用于应用。
详见官方文档:https://developer.android.google.cn/about/versions/pie/android-9.0-changes-28
建议
不要再使用httpClient来访问网络,替换成HttpURLConnection
临时快速解决方案
要继续使用 Apache HTTP 客户端,以 Android 9 及更高版本为目标的应用可以向其 AndroidManifest.xml的application节点下 添加以下内容:
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
示例:
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
<activity
android:name=".DisplayActivity"
android:configChanges="screenSize|orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>