首页 > 解决方案 > yarn android 错误“您必须为 Maven 存储库指定 URL”但它已经设置了吗?

问题描述

我需要构建并运行一个项目,我克隆了它,安装了依赖项,运行命令 yarn android 后,构建失败,控制台告诉我:

info Installing the app...
Starting a Gradle Daemon, 3 incompatible and 1 stopped Daemons could not be reused, use --status for details
                                Configuration on demand is an incubating feature.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> You must specify a URL for a Maven repository.

* 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 3m 21s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

error Command failed with exit code 1.

我检查了“您必须为 Maven 存储库指定 URL”这一行。并找出build.gradle文件应该包含一个 Maven URL,但我的已经有这个 URL:

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())


buildscript {
    ext {
        firebaseMessagingVersion =  "21.1.0"
        minSdkVersion = 23
        compileSdkVersion = 29
        targetSdkVersion = 29
        buildToolsVersion = "29.0.2"
        googlePlayServicesVersion = "17.0.0"
        multiDexEnabled=true
        supportLibVersion = "23.1.1" 
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.3")
        classpath 'com.google.gms:google-services:4.3.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        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")
        }
        jcenter()
        maven {
            url 'https://jitpack.io'
            url "https://maven.google.com"
             }
        maven {
            url = properties.getProperty ("bkm_maven_url")
            credentials {
                username = properties.getProperty ("bkm_username")
                password = properties.getProperty ("bkm_password")
            }
        }

        // force dependency versions on all subprojects
        configurations.all {
            resolutionStrategy {
                // use 0.9.0 to fix crash on Android 11
                force "com.facebook.soloader:soloader:0.9.0"
            }
        }
    }
}

我该如何解决这个问题?

标签: androidreact-nativemavengradle

解决方案


在测试了不同的方法后,我发现我应该只npm用来安装依赖项。我的意思是不要混合,yarn这解决了我的问题。


推荐阅读