Glide 在Android P 上圖片載入失敗!!!
原因
參考: ofollow,noindex">https://blog.csdn.net/qq_18620851/article/details/80617549
Android P 限制了明文流量的網路請求,非加密的流量請求都會被系統禁止掉。
如果當前應用的請求是 htttp 請求,而非 https ,這樣就會導系統禁止當前應用進行該請求,如果 WebView 的 url 用 http 協議,同樣會出現載入失敗,https 不受影響。
為此,OkHttp3 做了檢查,所以如果使用了明文流量,預設情況下,在 Android P 版本 OkHttp3 就丟擲異常: CLEARTEXT communication to " + host + " not permitted by network security policy
if (!Platform.get().isCleartextTrafficPermitted(host)) { throw new RouteException(new UnknownServiceException( "CLEARTEXT communication to " + host + " not permitted by network security policy")); }
解決方案
1:在 res 下新建一個 xml 目錄,然後建立一個名為:network_security_config.xml 檔案 ,該檔案內容如下:
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <base-config cleartextTrafficPermitted="true" /> </network-security-config>

檔案位置
2.然後在 AndroidManifest.xml application 標籤內應用上面的xml配置:
<application android:name=".App" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:networkSecurityConfig="@xml/network_security_config" android:roundIcon="@mipmap/ic_launcher_round" android:theme="@style/AppTheme"></application>

示例圖片
擴充套件
networkSecurityConfig介紹 https://developer.android.com/training/articles/security-config?hl=zh-cn