question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cannot load icons in android

See original GitHub issue

Environment

android, react-native 0.61.5, react-native-vector-icons 6.6.0, react-native-navigation v4

Description

I used rnn v4 and setting on tab icons.

import { PixelRatio } from 'react-native';
import DefaultIconProvider from 'react-native-vector-icons/EvilIcons';

import { isIphone } from 'constants/deviceinfo';

const navIconSize = isIphone ? 35 : PixelRatio.getPixelSizeForLayoutSize(35);

// Remove size string
const replaceSuffixPattern = /--(active|big|small|very-big)/g;
const icons = {
	'sc-youtube': [navIconSize],
	user: [navIconSize],
	gear: [navIconSize],
	search: [25],
	'chevron-right': [25],
};

const iconsSource = new Map();
const iconsLoaded = async () => {
	const sources = await Promise.all(
		Object.keys(icons).map(iconName => {
			const Provider = icons[iconName][1] || DefaultIconProvider;
			return Provider.getImageSource(
				iconName.replace(replaceSuffixPattern, ''),
				icons[iconName][0],
			);
		}),
	);

	Object.keys(icons).forEach((iconName, idx) => (iconsSource[iconName] = sources[idx]));

	return true;
};

(This is how I load icons for use tab button icons)

follow instructions and other solution issues, but simulators and real devices cant load icons like this.

스크린샷 2020-01-14 오후 2 34 38

I try to reinstall with cleaning project and also move to new react-native project, but don’t know why still can’t load icons.

Does anyone know a solution to this problem??

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

39reactions
raajnadarcommented, Apr 12, 2020

Use this command yarn react-native link react-native-vector-icons this will transfer all the files necessary to load the fonts in both android & ios folder.

Don’t use link cmd the latest cli version will throw warnings.

Automatic way to add fonts

Add this piece of code in android\app\build.gradle. I only want MaterialCommunityIcons.ttf if you want other font add them here it will be added automatically.

project.ext.vectoricons = [
	iconFontNames: ['MaterialCommunityIcons.ttf'] // Add fonts needed
]

`apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"`

This is manual way (If automatic didn’t work)

Step 1

Move the .ttf file from the node_modules\react-native-vector-icons\Fonts that you want to android\app\src\main\assets\fonts after that cd android and run ./gradlew clean or gradlew clean

Step 2

Add this line in android\app\build.gradle

project.ext.vectoricons = [
	iconFontNames: ['MaterialCommunityIcons.ttf', 'AnotherFont.ttf'] //name of all the fonts added from node_modules in step 1.
]

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

After that the icons will be visible. Try resetting the cache if it did not work yarn react-native start --reset-cache & yarn react-native run-android

12reactions
mainak-shilcommented, Jan 19, 2020

react-native link and re-run project works for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android application icon not showing up - Stack Overflow
I've just spent numerous hours constructing an icon for an Android app I'm working on, but can't get it to show up for...
Read more >
How to Fix App Icons Disappear/Not Showing in Android Phone
Fix App Icons Missing From Android Home Screen#MissingAndroidApps #AppIconsNotshowing AZ Screen ... Your browser can't play this video.
Read more >
Known issues with Android Studio and Android Gradle Plugin
Open the SDK Manager from Android Studio by clicking Tools > SDK Manager or click SDK Manager in the toolbar. Click the checkbox...
Read more >
Resources in Compose - Android Developers
Use the pluralStringResource API to load up a plural with a certain quantity. ... Jetpack Compose comes with the Icons object that is...
Read more >
Icon | Android Developers
java.lang.Object. ↳, android.graphics.drawable.Icon ... Much ink has been spilled on the best way to load images, ... Icon, This value cannot be null...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found