Build failed exception when adding vector icons to a react native project

3.4k Views Asked by At

I have to use vector icons in my react native projects, while doing the build (react-native run-android) for android platform I get this error.

Did these steps to add vector Icons:

npm install react-native-vector-icons –save

react-native link

Can anyone help to resolve this issue?

FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring project ':app'.

Could not resolve all dependencies for configuration ':app:_debugApk'. A problem occurred configuring project ':react-native-vector-icons'. Could not resolve all dependencies for configuration ':react-native-vector-icons:classpath'. Could not resolve com.android.tools.build:gradle:2.3.+. Required by: crm:react-native-vector-icons:unspecified Could not resolve com.android.tools.build:gradle:2.3.+. Failed to list versions for com.android.tools.build:gradle. Unable to load Maven meta-data from https://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml. Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml'. jcenter.bintray.com:443 failed to respond

3

There are 3 best solutions below

0
On

Don't do link with android, the recommended option is with gradle, they have provided it. Gradle always works for me

0
On

please check in your project android folder is these things done, if not please do them you can also go through this link react-native-vector-icons android manual installation

Edit android/settings.gradle to look like this (without the +):
rootProject.name = 'MyApp'
include ':app'
+ include ':react-native-vector-icons'
+ project(':react-native-vector-icons').projectDir = new 
File(rootProject.projectDir, '../node_modules/react-native-vector- 
icons/android')
Edit android/app/build.gradle (note: app folder) to look like this:

apply plugin: 'com.android.application'

android {
 ...
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+"  // From node_modules
+ compile project(':react-native-vector-icons')
}


Edit your MainApplication.java (deep in 
android/app/src/main/java/...) to look like this (note two places to 
edit):

package com.myapp;

+ import com.oblador.vectoricons.VectorIconsPackage;

....

@Override
protected List<ReactPackage> getPackages() {
 return Arrays.<ReactPackage>asList(
   new MainReactPackage()
 +   , new VectorIconsPackage()
 );
}

}

if then also problem occurs just clean the android project either by android studio or command line, for command line goto

project/android/app and run

./gradlew clean

0
On

Edit: update the gradle command

You just need run commands:

cd android

./gradlew clean

Hope it can help.