適配Bugly不支持Android P

Bugly官方文檔上最高是適配的8.x,剛開始的時候我拿Android P進行測試也是無效果.后來發(fā)現(xiàn)log中有一句Cleartext HTTP traffic to android.bugly.qq.com not permitted. 拿起就是一陣Google,發(fā)現(xiàn)原來是Android P需要進行適配(限制了明文流量的網(wǎng)絡請求,非加密的流量請求都會被系統(tǒng)禁止掉). 當我發(fā)現(xiàn)這個的時候,仿佛看到了一絲光明,抱著試一試的心態(tài),搞了一下,果然可行.(測試機型為Pixel 2,Android 9.0)

1. Android 9.0 適配

Android 9.0上會報以下錯誤,聯(lián)網(wǎng)會失敗:

2018-10-10 16:39:21.312 31611-31646/com.xfhy.tinkerfirmdemo W/CrashReport: java.io.IOException: Cleartext HTTP traffic to android.bugly.qq.com not permitted
        at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:115)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:458)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:258)
        at com.tencent.bugly.proguard.ai.a(BUGLY:265)
        at com.tencent.bugly.proguard.ai.a(BUGLY:114)
        at com.tencent.bugly.proguard.al.run(BUGLY:355)
        at com.tencent.bugly.proguard.ak$1.run(BUGLY:723)
        at java.lang.Thread.run(Thread.java:764)
2018-10-10 16:39:21.312 31611-31646/com.xfhy.tinkerfirmdemo E/CrashReport: Failed to upload, please check your network.
2018-10-10 16:39:21.312 31611-31646/com.xfhy.tinkerfirmdemo D/CrashReport: Failed to execute post.
2018-10-10 16:39:21.312 31611-31646/com.xfhy.tinkerfirmdemo E/CrashReport: [Upload] Failed to upload(1): Failed to upload for no response!
2018-10-10 16:39:21.313 31611-31646/com.xfhy.tinkerfirmdemo E/CrashReport: [Upload] Failed to upload(1) userinfo: failed after many attempts

解決辦法

  • 具體原因:Android P - CLEARTEXT communication not permitted by network security policy 詳細介紹

在資源文件新建xml目錄,新建文件
network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">android.bugly.qq.com</domain>
    </domain-config>
</network-security-config>

然后在清單文件中application下加入android:networkSecurityConfig="@xml/network_security_config"即可

?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容