React-Native:无法在Android设备上的发布模式下显示远程图像 [英] React-Native : Can't show remote images in release mode on android device

查看:131
本文介绍了React-Native:无法在Android设备上的发布模式下显示远程图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im在我的android设备(三星9,Android 9,API 28)中运行一个简单的本机应用程序,因此在调试模式下,使用以下命令行即可正常工作:

im runing a simple react-native application in my android device (samsung 9, Android 9, API 28), so on debug mode it's work fine using this commande line :

react-native run-android

这是结果:

但处于释放模式(react-native run-android --variant=release),图像未显示:

but in relase mode (react-native run-android --variant=release) , image not showing :

我的简单代码:

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
      <Image source={ {uri:'http://i.imgur.com/GRIZj68.png'} } style={{width:200,height:200} } />
      <Text>HOLA</Text>  
      </View>
    );
  }
}

请帮忙!

推荐答案

Android pie(9)不允许呈现非https图像,因此您必须将http请求更改为https或设置networkSecurityConfig在您的Manifest应用程序标签中,如下所示:

Android pie (9) doesn't allow non https images to be rendered, so you have to change your http requests to https or to set a networkSecurityConfig in your Manifest application tag like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config">
    </application>
</manifest>

然后,您现在必须在xml文件夹中创建一个名为network_security_config的文件,就像在清单中命名该文件一样,从那里开始,文件内容应像这样,以启用所有不加密的请求:

Then in your xml folder you now have to create a file named network_security_config just like the way you have named it in the Manifest and from there the content of your file should be like this to enable all requests without encryptions:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

来源:https://developer.android.com/training/articles/security-config

这篇关于React-Native:无法在Android设备上的发布模式下显示远程图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆