Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local images are not visible in React-Native app release build

In my react-native app I have "src" folder that includes a Images folder and screens folder.My screens folder have various components where I am uing local images from Images using following code.

<Image source={require('src/Images/logo.png')} />

logo.png is an image placed in Images folder, there are many more such images referenced like this.Now all these images are shown pretty well in development mode but when I generated the release apk using gradlew assemblereleaseand installed the apk on my device all images referenced in this manner disappear somewhere.

My react-native version is 0.40.

like image 257
Manjeet Singh Avatar asked Jan 30 '17 13:01

Manjeet Singh


People also ask

How do I display images in React Native app?

Adding Image Let us create a new folder img inside the src folder. We will add our image (myImage. png) inside this folder. We will show images on the home screen.

How do I display local images in React?

To display an image from a local path in React:Download the image and move it into your src directory. Import the image into your file, e.g. import MyImage from './thumbnail. webp' . Set the src prop of the image element to the imported image, e.g. <img src={MyImage} alt="horse" /> .

How do I display a JPEG in React Native?

Open App. js and add the following code: import { StatusBar } from "expo-status-bar"; import React from "react"; import { StyleSheet, Text, View, ImageBackground } from "react-native"; const staticImage = require("./src/assets/static-image. png"); export default function App() { return ( <View style={styles.


2 Answers

Solved by following answer of Chiranjhivi Ghimire Steps -

  1. Created assets folder at ../android/app/src/main/
  2. copy and paste this command in command prompt

react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

  1. enter this command in cmd gradle assemblerelease.
  2. done

equivalent solution for ios can be found at link

like image 65
Manjeet Singh Avatar answered Oct 09 '22 11:10

Manjeet Singh


try running this
npm start --reset-cache

like image 28
chris Avatar answered Oct 09 '22 11:10

chris