今天用我自己的手機安裝我正在開發的APP的時候,出現閃退現象,我手機Android9的,在此記錄下原因
首先呢,Android8一閃的手機需要配置以下權限,大概就是允許安裝未知應用的權限吧(我也不太瞭解,猜的,反正加上就是了)
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
然後Android9的手機安裝閃退,並且報:
Android9.0_P:ClassNotFoundException:Didn't find class "org.apache.http.ProtocolVersion" on path:XXXXX
這麼一個錯。
需要在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閃退的問題就解決啦!