AndroidStudio在Android9上调试闪退的问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36611526/article/details/89466341

今天用我自己的手机安装我正在开发的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闪退的问题就解决啦!

猜你喜欢

转载自blog.csdn.net/qq_36611526/article/details/89466341
今日推荐