I'm learning react native expo
I want to require an image from assets/images
The image I want to require is noti.png
I got this error
What am i missing?
You are passing the location of the image incorrectly. as you can see in the error: the module .. could not be found
To fix it, check the location of current file you are calling that image then go back to the exact location and call it. Also If you are using IDE they recommend you the location.
Update:
require('../assets/images/noti.png'
Related
Is there a way to clear cache in webview for both ios and android?
I tried using #react-native-community_cookies, it works for ios, but for android Im getting this error when trying to run: A problem occurred evaluating project ':#react-native-community_cookies'. > Plugin with id 'maven' not found.
Maybe any of you have suggestions how to fix this or know some other methods?
Thanks
You can use this plugin https://www.npmjs.com/package/#react-native-community/cookies for clear cache and write below function
import CookieManager from '#react-native-community/cookies';
CookieManager.clearAll(true)
The true param means that it will clear cookies for the webkit webview (which is what this library uses)
Check out this library it does the job done.
https://github.com/react-native-cookies/cookies
import CookieManager from '#react-native-cookies/cookies';
CookieManager.clearAll(true);
according to expo documentation:
The most straightforward way to provide an icon for your app is to provide the icon key in app.json
so I added my own icon to the assets folder where expo's default icons are, and modified app.json to point to my icon:
"expo": {
...
"icon": "./assets/myIcon.png"
}
but when launching I get this error from expo:
Field: icon - cannot access file at './assets/myIcon.png
what am I missing? where should I put my Icon picture?
Solved
by running expo start -c to clear cache.
*Note: it took me a few minutes to sync with my expo client app!
Based on the conversation that I had with the question poster (#Blue Turtle) there are some take aways from this.
Image sizes
It is important to make sure that the image that you are using for your icon must be a perfect square. If it is not Expo will give an error similar to below
Error: Problems validating asset fields in app.json. See https://docs.expo.io/
• Field: icon - image should be square, but the file at './assets/icon.png' has dimensions 1242x2436.
The documents recommend that you use an image that has size 1024x1024 https://docs.expo.io/versions/latest/workflow/configuration/#icon
Local path or remote url to an image to use for your app's icon. We
recommend that you use a 1024x1024 png file. This icon will appear on
the home screen and within the Expo app.
Clearing the cache
Also when updating assets etc, it is advisable to close and restart your bundler, restarting using the following command expo start -c. Starting the bundler this way will ensure that your cache is cleared and that any changes that you have made to packages, assets etc will be made and you will hopefully experience less errors.
Building a React Native app with Expo, the Javascript bundle fails after getting the error Unable to resolve "../stores/__fixtures__/matchlist/matchlistSourceFixture" from "src/containers/MatchlistSwipeContainer.tsx", despite the fact that I am 100% sure this file exists and its relative path in this instance is correct – especially as I’m using VSCode and it complains if the path isn’t right and I’m using VSCode’s autocomplete to begin with.
If I move the file into any other directory that is not with __ dunder affixes and update the relative path accordingly, it can find the file perfectly fine.
I’ve checked other similar topics with Unable to resolve module errors, but they all seem to be related to third-party packages, whereas this is a local file.
Import statement:
import { matchlistSourceFixture } from '../stores/__fixtures__/matchlist/matchlistSourceFixture';
Export statement in the file in matchlistSourceFixture.ts:
export const matchlistSourceFixture = {...}
Attached is an image of the error message in the Expo iOS app. The message stating that the file doesn’t even exist (it has a .ts extension by the way) makes me think the relative path isn’t really the issue here anyway.
Versions:
React 16.3.1
Expo 27.0.0
Exp 54.0.0
It seems like __fixtures__ dirs are blacklisted by default in RN: react-native/local-cli/util/Config.js.
See this comment on overriding the default.
Hope you could help me here:
I'm currently building an app which I created through CRNA and then ejected. I get the ios version right on but I'm currently struggling a lot with the android version.
When running react-native run-android all I can get is the following error:
Error type 3
Error: Activity class {com.myapp/com.myapp.MainActivity} does not exist.
I've checked app/build.gradle, app/src/main/AndroidManifest.xml, app/src/main/java/com/myapp/MainActivity.java and app/src/main/java/com/myapp/MainActivity.java for name errors on package. I've tried moving from com.myapp to com.mebius.myapp and com aswell.
Seems this comes from the only plugin I'm using. I'm keeping on the investigation
Any hints?
There are 3 possible reasons for the android app build fails to make
1. You need to define sdk path in android/local.properties
if local.properties doesn't place then make a file names with that
add
sdk.dir = home/user/AndroidApp/local/Sdk
You can match with their system path..
2. Your genymotion or avd must enable with the android studio
3. You must have to go with the following command
npm start
in new terminal .
Please go through with it.
Thanks
Actually I had a problem with my gradle config which look like:
include ':react-native-sensors'
project(':react-native-sensors').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sensors/android')
rootProject.name = 'accelapp'
I needed to add: include ':app'
I don't know if it's due to the process of ejecting from CRNA or if it's due to react-native link react-native-sensors though.
EDIT After some investigation, I couldn't reproduce this issue. This leads me to say it was a faulty copy/paste...
11:01:29: Failed building JavaScript bundle
11:01:29: Unable to resolve ./app/img/grangologo.png" from ".//App.js: could not resolve/home/gokul/React/Grango/app/img/grangologo.png' as a file nor as a folder","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]},"type":"bundling_error"}"
you'r path to the image is wrong, try to use some console.log's to check yourself if the image was imported.
(p.s you could avoid all of it by using proper editor)