您可能只希望在调试时允许使用cleartext,但要保留在生产中拒绝使用cleartext的安全好处。这对我很有用,因为我在不支持https的开发服务器上测试我的应用程序。下面是如何在生产中强制使用https,但在调试模式下允许使用cleartext:
在build.gradle中:
// Put this in your buildtypes debug section:
manifestPlaceholders = [usesCleartextTraffic:"true"]
// Put this in your buildtypes release section
manifestPlaceholders = [usesCleartextTraffic:"false"]
在androidmanifest.xml中的应用程序标记中
android:usesCleartextTraffic="${usesCleartextTraffic}"