React Native 配置项目“:app”时出现问题

9wbgstp7  于 2022-12-24  发布在  React
关注(0)|答案(2)|浏览(186)

尝试react-native run-android时出错。我不知道为什么会出错。

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 find any matches for com.android.tools.build:gradle:2.3.+ as no versions of com.android.tools.build:gradle are available.

android\build.gradle的配置文件如下所示。

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
   }
}

allprojects {
repositories {
    mavenLocal()
    jcenter()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is 
 installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
 }
}

Gradle版本:3.3,插件:2.2.3

wkftcu5l

wkftcu5l1#

1.升级package.json中的react-native-vector-icons: "^6.0.2"
1.然后运行npm i react-native-vector-icons
1.作为最后一步,cd android && ./gradlew clean

lmvvr0a8

lmvvr0a82#

依赖项更改自:
第一个月
致:
dependencies { compile "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}" }
同时更改构建脚本依赖项以使用:classpath 'com.android.tools.build:gradle:2.2.3'maven { url "https://dl.bintray.com/android/android-tools/" },而不是google()
因此,您的../node_modules/react-native-vector-icons/android/build. gradle应该如下所示:

buildscript {
  repositories {
    maven { url "https://dl.bintray.com/android/android-tools/" }
    jcenter()
  }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}

apply plugin: 'com.android.library'

def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

android {
  compileSdkVersion safeExtGet('compileSdkVersion', 26)
  buildToolsVersion safeExtGet('buildToolsVersion', '26.0.3')

  defaultConfig {
    minSdkVersion safeExtGet('minSdkVersion', 16)
    targetSdkVersion safeExtGet('targetSdkVersion', 26)
    versionCode 1
    versionName "1.0"
  }
  lintOptions {
    abortOnError false
  }
}

repositories {
  mavenCentral()
}

dependencies {
  compile "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
}

相关问题