Android9的问题
首先需要在AndroidManifest.xml文件的application标签里面加入
<uses-library android:name="org.apache.http.legacy" android:required="false" />
然后添加该权限:
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
在AndroidManifest.xml的application节点下 添加以下内容:
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
<application
android:name=".application.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:largeHeap="true"
android:theme="@style/QMUI.Compat.NoActionBar"
tools:ignore="GoogleAppIndexingWarning">
<!--android9闪退-->
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
加上这么一段代码之后呢,ClassNotFoundException的错是不报了,但是还是闪退,并给你一个
java.io.IOException: Cleartext HTTP traffic to xxx.xxx.xxx.xxx not permitted
这样的错,网上找了一下据说是Android9.0 默认是禁止所有的http请求的,我们还需要在AndroidManifest.xml的application节点中加上android:usesCleartextTraffic="true"属性,如下:
<application
android:name=".application.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:largeHeap="true"
android:theme="@style/QMUI.Compat.NoActionBar"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<!--android9闪退-->
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
这样Android9闪退的问题就解决啦!
原文:https://blog.csdn.net/qq_36611526/article/details/89466341