Android程序在Android9.0手机或者虚拟机上运行不了的解决方法

1、在虚拟机上我使用的是Android5.0版本,当前manifests的application标签配置如下,正确运行没问题。

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="qsj_weather_task_6"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        
        android:theme="@style/AppTheme">

        <activity android:name="com.example.qsj_weather_task_6.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

2、但是放到真机上(Android 9)就会闪退,于是在application标签里面添加一行代码:android:usesCleartextTraffic=“true”。就可以正确运行了。

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="qsj_weather_task_6"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:usesCleartextTraffic="true"
        android:theme="@style/AppTheme">

        <activity android:name="com.example.qsj_weather_task_6.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

发布了1 篇原创文章 · 获赞 1 · 访问量 36

猜你喜欢

转载自blog.csdn.net/weixin_43779451/article/details/104718299