我正在用本机运行一个项目(来自“全栈本机响应”的联系人)。但是我对react-native-vector-icons有问题。
当我运行react-native run-android
时,它显示出以下错误:
D:\android_Project\Vitel\React_Nativ\test\ZContacts>react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using
"--no-jetifier" flag.
Jetifier found 874 file(s) to forward-jetify. Using 8 workers...
info JS server already running.
info Installing the app...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':react-native-vector-icons'.
> Could not resolve all artifacts for configuration ':react-native-vector-icons:
classpath'.
> Could not find aapt2-proto.jar (com.android.tools.build:aapt2-proto:0.3.1).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2-p
roto/0.3.1/aapt2-proto-0.3.1.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 48s
error Failed to install the app. Make sure you have the Android development envi
ronment set up: https://facebook.github.io/react-native/docs/getting-started.htm
l#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8
081
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':react-native-vector-icons'.
> Could not resolve all artifacts for configuration ':react-native-vector-icons:
classpath'.
> Could not find aapt2-proto.jar (com.android.tools.build:aapt2-proto:0.3.1).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2-p
roto/0.3.1/aapt2-proto-0.3.1.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 48s
at checkExecSyncError (child_process.js:629:11)
at execFileSync (child_process.js:647:13)
at runOnAllDevices (D:\android_Project\Vitel\React_Nativ\test\ZContacts\node
_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\
runOnAllDevices.js:94:39)
at buildAndRun (D:\android_Project\Vitel\React_Nativ\test\ZContacts\node_mod
ules\@react-native-community\cli-platform-android\build\commands\runAndroid\inde
x.js:158:41)
at then.result (D:\android_Project\Vitel\React_Nativ\test\ZContacts\node_mod
ules\@react-native-community\cli-platform-android\build\commands\runAndroid\inde
x.js:125:12)
at process._tickCallback (internal/process/next_tick.js:68:7)
我的Build.gradle是:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
}
repositories {
google()
jcenter()
}
dependencies {
classpath('com.android.tools.build:gradle:3.5.0')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
和app / build.gradle是:
apply plugin: "com.android.application"
import com.android.build.OutputFile
def enableHermes = project.ext.react.get("enableHermes", false);
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.zcantacts"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://facebook.github.io/react-native/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
再次我试图运行一个新的简单项目,所以我执行以下命令: 我用这个逗号尝试了一个新的简单项目:
>react-native init testicons
>cd testicons
将build.gradle更改(将classpath(“ com.android.tools.build:gradle:3.4.2”)更改为classpath(“ com.android.tools.build:gradle:3.5.0”) ) 然后应用程序以react-native run-android运行(无需从react-native-vector-icons导入) 并运行以下命令:
>npm install react-native-vector-icons
和
>react-native link react-native-vector-icons
我更改了app.js:
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React from 'react';
import {View,} from 'react-native';
import { MaterialIcons } from 'react-native-vector-icons';
const getTabBarIcon = icon => ({ tintColor }) => (
<MaterialIcons name={icon} size={26} style={{ color: tintColor }} />
);
const App: () => React$Node = () => {return (<><View >{getTabBarIcon('list')}</View></>);};
export default App;
但是当我运行波纹管照相机时,我和以前有同样的错误!
react-native run-android
那个错误是:
D:\android_Project\Vitel\React_Nativ\testicons>react-native run-android
error React Native CLI uses autolinking for native dependencies, but the followi
ng modules are linked manually:
- react-native-vector-icons (to unlink run: "react-native unlink react-native-
vector-icons")
This is likely happening when upgrading React Native from below 0.60 to 0.60 or
above. Going forward, you can unlink this dependency via "react-native unlink <d
ependency>" and it will be included in your app automatically. If a library isn'
t compatible with autolinking, disregard this message and notify the library mai
ntainers.
Read more about autolinking: https://github.com/react-native-community/cli/blob/
master/docs/autolinking.md
info Running jetifier to migrate libraries to AndroidX. You can disable it using
"--no-jetifier" flag.
Jetifier found 867 file(s) to forward-jetify. Using 8 workers...
info JS server already running.
info Installing the app...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':react-native-vector-icons'.
> Could not resolve all artifacts for configuration ':react-native-vector-icons:
classpath'.
> Could not find aapt2-proto.jar (com.android.tools.build:aapt2-proto:0.3.1).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2-p
roto/0.3.1/aapt2-proto-0.3.1.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 28s
error Failed to install the app. Make sure you have the Android development envi
ronment set up: https://facebook.github.io/react-native/docs/getting-started.htm
l#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8
081
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':react-native-vector-icons'.
> Could not resolve all artifacts for configuration ':react-native-vector-icons:
classpath'.
> Could not find aapt2-proto.jar (com.android.tools.build:aapt2-proto:0.3.1).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2-p
roto/0.3.1/aapt2-proto-0.3.1.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 28s
at checkExecSyncError (child_process.js:629:11)
at execFileSync (child_process.js:647:13)
at runOnAllDevices (D:\android_Project\Vitel\React_Nativ\testicons\node_modu
les\@react-native-community\cli-platform-android\build\commands\runAndroid\runOn
AllDevices.js:94:39)
at buildAndRun (D:\android_Project\Vitel\React_Nativ\testicons\node_modules\
@react-native-community\cli-platform-android\build\commands\runAndroid\index.js:
158:41)
at then.result (D:\android_Project\Vitel\React_Nativ\testicons\node_modules\
@react-native-community\cli-platform-android\build\commands\runAndroid\index.js:
125:12)
at process._tickCallback (internal/process/next_tick.js:68:7)
你能帮我吗?什么是问题,我该如何解决?
答案 0 :(得分:-1)
关注此 https://github.com/oblador/react-native-vector-icons#android
或者您可以做到
react-native link react-native-vector-icons