简体   繁体   English

将矢量图标添加到本机项目时构建失败的异常

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

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.我必须在我的本机项目中使用矢量图标,而在为 android 平台进行构建 (react-native run-android) 时,我收到此错误。

Did these steps to add vector Icons:是否按以下步骤添加矢量图标:

npm install react-native-vector-icons –save npm install react-native-vector-icons –save

react-native link反应原生链接

Can anyone help to resolve this issue?任何人都可以帮助解决这个问题吗?

FAILURE: Build failed with an exception. FAILURE:构建失败,出现异常。 * What went wrong: A problem occurred configuring project ':app'. * 出了什么问题:配置项目“:app”时出现问题。

Could not resolve all dependencies for configuration ':app:_debugApk'.无法解析配置“:app:_debugApk”的所有依赖项。 A problem occurred configuring project ':react-native-vector-icons'.配置项目 ':react-native-vector-icons' 时出现问题。 Could not resolve all dependencies for configuration ':react-native-vector-icons:classpath'.无法解析配置 ':react-native-vector-icons:classpath' 的所有依赖项。 Could not resolve com.android.tools.build:gradle:2.3.+.无法解析 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.+.需要:crm:react-native-vector-icons:unspecified 无法解析 com.android.tools.build:gradle:2.3.+。 Failed to list versions for com.android.tools.build:gradle.无法列出 com.android.tools.build:gradle 的版本。 Unable to load Maven meta-data from https://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml .无法从https://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml加载 Maven 元数据。 Could not GET ' https://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml '.无法获取“ https://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml ”。 jcenter.bintray.com:443 failed to respond jcenter.bintray.com:443 未能响应

Edit: update the gradle command编辑:更新 gradle 命令

You just need run commands:你只需要运行命令:

cd android光盘安卓

./gradlew clean ./gradlew 干净

Hope it can help.希望它能有所帮助。

Don't do link with android, the recommended option is with gradle, they have provided it.不要用android做链接,推荐的选项是gradle,他们已经提供了。 Gradle always works for me Gradle 总是对我有用

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请检查您的项目android文件夹是否完成了这些事情,如果没有请您也可以通过此链接react-native-vector-icons android手动安装

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如果然后也出现问题,只需通过 android studio 或命令行清理 android 项目,对于命令行goto

project/android/app and run项目/android/app 并运行

./gradlew clean ./gradlew 干净

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM