问题描述
昨天我获得了Android N预览的新升级。自从我升级以来,我再也无法启动我的应用了。
Yesterday I got a new upgrade for the Android N preview. Ever since I upgraded, I cannot start my app anymore.
java.io.IOException: Cleartext HTTP traffic to myserver.com not permitted
我试图将 usesCleartextTraffic
设置为 true $ c清单中的$ c>或添加
network_security_config.xml
I have tried to set the usesCleartextTraffic
to true
in the manifest or to add a network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">myserver.com</domain>
</domain-config>
</network-security-config>
两者都没有奏效。关于那里发生了什么的任何想法?
Neither did work. Any ideas about what is going on there?
当我尝试在清单中定义networkSecurityConfig时,我收到编译错误
When I try to define networkSecurityConfig in the manifest, I get a compile error
Error:(35) No resource identifier found for attribute 'networkSecurityConfig' in package 'android'
不确定原因。文件就在那里,一切都很好。
Not really sure why. The file is there and everything looks good.
发现建议。他们建议将 network_security_config
定义移至元数据
。我仍然得到相同的异常。
Found this suggestion in the Android issue tracker from Google. They suggest to move the network_security_config
definition to the meta-data
. I still get the same exception though.
推荐答案
Android N Developer Preview 4中存在一个已知问题,如果应用修改了它的 ApplicationInfo.flags
,它会触发阻止来自应用程序的明文流量,即使应用程序没有请求阻止明文流量。修复程序位于下一个开发人员预览版中。因此,这与您的网络安全配置无关。实际上,您甚至不需要声明自定义网络安全配置。
There is a known issue in Android N Developer Preview 4 where, if an app modifies its ApplicationInfo.flags
, it triggers the blocking of cleartext traffic from the app, even if the app didn't request cleartext traffic to be blocked. The fix is in the next Developer Preview. Thus, this has nothing to do with your Network Security Config. In fact, it looks like you don't even need to declare a custom Network Security Config.
如果您不能等到下一个Android N开发者预览版,请检查您的应用程序适用于修改自己的 ApplicationInfo.flags
的地方。通常,它采用 getApplicationInfo()。flags& = ApplicationInfo.FLAG_DEBUGGABLE
或 getApplicationInfo()。flags = ApplicationInfo.FLAG_DEBUGGABLE $ c的形式$ C>。这些用法的修复是
(getApplicationInfo()。flags& ApplicationInfo.FLAG_DEBUGGABLE)
。
If you can't wait until the next Android N Developer Preview, check your app for places where it modifies its own ApplicationInfo.flags
. Typically this takes the form of getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE
or getApplicationInfo().flags = ApplicationInfo.FLAG_DEBUGGABLE
. The fix for these usages is (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)
.
或者,as解决方法,尽可能早地在应用程序的生命周期中调用 NetworkSecurityPolicy.isCleartextTrafficPermitted()
。如果在篡改 ApplicationInfo.flags
的代码之前调用此解决方法应该有效。
Alternatively, as a workaround, invoke NetworkSecurityPolicy.isCleartextTrafficPermitted()
as early in your app's lifecycle as possible. This workaround should work if invoked before the code which tampers with ApplicationInfo.flags
.
这篇关于在Android N预览中不允许使用Cleartext到myserver.com的HTTP流量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!