React-Native:无法解析配置 ':app:debugCompileClasspath'的所有依赖项

标签 react-native gradle

我对 react 性的事物有点陌生,所以请原谅我可能犯了愚蠢的错误。

在发布到这里之前,我基本上尝试了所有可以找到的东西,但现在不确定这是否是我自己的事情(又称我是愚蠢的)还是由于某处最近的更新而导致的错误。

因此,我的问题是上面提到的错误消息,在尝试构建应用程序时(通过使用react-native run-android或什至是gradlew clean),我都会收到该错误消息。我在下面发布了完整的错误消息以及我的app/build.gradle,build.gradle和settings.gradle文件。

我保留了所有文件的“react-native init”创建方式,并“只是”根据各自库的安装指南添加了必须添加的命令。

由于Firebase SDK的最新更改,在gradle版本等方面,我不得不作了很多更改。这就是为什么我想知道此问题是否与此有关?

哦,还有版本号:

"dependencies": {
"babel-core": "^6.26.3",
"eslint": "^4.19.1",
"fbjs": "^0.8.16",
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-firebase": "^4.1.0",
"react-native-navigation": "^1.1.458",
"react-native-vector-icons": "^4.6.0",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.2.0"
}

我为每个软件包都安装了yarn(yarn add react-native-vector-icons等)和npm(npm install以及npm install react-native-vector-icons等),以确保与任何软件包都不相关。在这之间,我当然删除了整个node_modules文件夹。react-native link都没有帮助。

它也不仅限于所提到的react-native-vector-icons包:我从项目中完全删除了它,并且另一个包也弹出了相同的错误。

我感谢任何帮助和提示!

提前非常感谢您!

达斯汀

错误信息:
FAILURE: Build failed with an exception.

    * What went wrong:
    A problem occurred configuring project ':app'.
    > Could not resolve all dependencies for configuration ':app:debugCompileClasspath'.
       > More than one variant of project :react-native-vector-icons matches the consumer attributes:
           - Configuration ':react-native-vector-icons:debugApiElements' variant android-aidl:
               - Found artifactType 'android-aidl' but wasn't required.
               - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
               - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
               - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
               - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
           - Configuration ':react-native-vector-icons:debugApiElements' variant android-classes:
               - Found artifactType 'android-classes' but wasn't required.
               - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
               - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
               - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
               - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
           - Configuration ':react-native-vector-icons:debugApiElements' variant android-manifest:
               - Found artifactType 'android-manifest' but wasn't required.
               - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
               - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
               - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
               - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
           - Configuration ':react-native-vector-icons:debugApiElements' variant android-renderscript:
               - Found artifactType 'android-renderscript' but wasn't required.
               - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
               - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
               - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
               - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
           - Configuration ':react-native-vector-icons:debugApiElements' variant jar:
               - Found artifactType 'jar' but wasn't required.
               - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
               - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
               - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
               - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.

APP/BUILD.GRADLE:
apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    entryFile: "index.js"
]

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

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"

    defaultConfig {
        applicationId "com.seroleashed.budgetmanager"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            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:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            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 {
    compile project(':react-native-vector-icons')
    compile project(':react-native-navigation')
    compile(project(':react-native-firebase')) {
        transitive = false
    }
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-navigation')
    implementation "com.android.support:appcompat-v7:27.0.1"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation project(':react-native-firebase')
    // RNFirebase required dependencies
    implementation "com.google.android.gms:play-services-base:15.0.0"
    implementation "com.google.firebase:firebase-core:15.0.2"
    implementation "com.google.firebase:firebase-auth:15.1.0"
    implementation "com.google.firebase:firebase-database:15.0.0"
    implementation "com.google.firebase:firebase-messaging:15.0.2"
}

// 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 plugin: 'com.google.gms.google-services'

建档:
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:3.3.0'
        // 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"
        }

        google()
    }
}

SETTINGS.GRADLE:
rootProject.name = 'BudgetManager'
include ':app'
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app')
include ':react-native-firebase'
project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android')
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native

最佳答案

google()移到顶部有时可以解决类似的问题。
您的代码中的示例修复

buildscript {
    google()
    repositories {
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:3.3.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenLocal()
        jcenter()
        maven {
            url "$rootDir/../node_modules/react-native/android"
        }  
    }
}

关于React-Native:无法解析配置 ':app:debugCompileClasspath'的所有依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50348927/

相关文章:

react-native - 在代码中重新加载 react native 应用程序

gradle - 无法确定 Gradle 为什么在配置阶段下载 compileClasspath 依赖项

intellij-idea - 将另一个 gradle 项目导入现有的 android 项目时,Android Studio 访问被拒绝

react-native - Native-base 不适用于 react-native 0.57.1​​?

javascript - 如何将 React 开发工具与 React Native 一起使用?

react-native - React Native regex 导致 iOS 11.2 崩溃

ios - 将 Expo React native 应用程序从 Windows 操作系统上传到 Testflight

android - Gradle插件,在构建过程中两次运行任务

gradle - 如何为 buildSrc 和应用程序模块定义 Kotlin 版本?

android - 在 Android Studio 项目中添加外部项目作为依赖导致找不到文件的错误