React-Native : Can't show remote images in release mode on android device

后端 未结 2 536
有刺的猬
有刺的猬 2021-01-25 17:30

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         


        
相关标签:
2条回答
  • 2021-01-25 18:22

    We were having crashes and issues in development with our icons not being written out and appearing like images_homeactive. This caused react-native-navigation to crash our app

    This occurred when we upgraded to compileSDKVersion = 28.

    Starting with Android 9 (API level 28), cleartext support is disabled by default

    this prevents your application from connecting to the React Native packager. The changes below allow cleartext traffic in debug builds.

    ../app/src/main/AndroidManifest.xml
    <application
        ...
        android:usesCleartextTraffic="${isDebug}" tools:targetApi="28">
    
    ../android/app/build.gradle
    buildTypes {
        release {
            ...
            manifestPlaceholders = [isDebug:false]
        }
        debug {
            ...
            manifestPlaceholders = [isDebug:true]
        }
    }
    

    So thankful to stumble upon Ahmed's answer. Hope this helps someone.

    0 讨论(0)
  • 2021-01-25 18:32

    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>
    

    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>
    

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

    0 讨论(0)
提交回复
热议问题