【问题标题】:How to add an additional Maven repository to Android Studio build如何向 Android Studio 构建添加额外的 Maven 存储库
【发布时间】:2022-01-20 18:01:09
【问题描述】:

我已将以下内容添加到我的应用程序build.gradledependencies 部分中

implementation 'org.seleniumhq.selenium:selenium-htmlunit-driver:3.56.0'

但我得到了错误:

Could not find org.seleniumhq.selenium:selenium-htmlunit-driver:3.56.0.
Searched in the following locations:
   - https://dl.google.com/dl/android/maven2/org/seleniumhq/selenium/selenium-htmlunit-driver/3.56.0/selenium-htmlunit-driver-3.56.0.pom

   - https://repo.maven.apache.org/maven2/org/seleniumhq/selenium/selenium-htmlunit-driver/3.56.0/selenium-htmlunit-driver-3.56.0.pom

   - https://jcenter.bintray.com/org/seleniumhq/selenium/selenium-htmlunit-driver/3.56.0/selenium-htmlunit-driver-3.56.0.pom
 Required by:
     project :app

所以在项目build.gradle文件中,我添加到repositories部分:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()

        // ADDED THIS 2021 12 17
        maven {
            url("https://mvnrepository.com")
        }

        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.3"
    }
}

我认为这会起作用,因为当我使用浏览器导航时,有一个带有selenium-htmlunit_driver_3.56.0 的页面,域mvnrepository.com

我所期望的是会找到指定的依赖项。或者,我会得到一份报告,其中将在“在以下位置搜索:”下包含另一行,但将该行添加到项目 build.grade 中无效。

我需要做什么才能搜索到额外的 Maven 存储库?从 mavenCentral() 条目 (repo.maven.apache.org/maven2...) 中提取的 maven 存储库不包含我想尝试的 selenium-htmlunit-drive 版本。

这是使用 Artic Fox 2020.3.1 补丁 3。

我做错了什么?

【问题讨论】:

    标签: android-studio maven build dependencies


    【解决方案1】:

    试试这个网址:https://repo1.maven.org/maven2

    文件可在此处获得:Link

    mvnrepository.com 只是搜索依赖项的前端,而不是带有 jar 文件本身的文件系统。

    【讨论】:

      【解决方案2】:

      Artic Fox 开始使用基于 depedencyResolutionManagment 的另一种技术,该技术引入了这种令人头疼的情况,即不搜索应用程序级 build.grade 文件中的条目。

      在这种情况下对我有用的是进入settings.gradle(而不是build.gradle并更改:

      repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

      repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

      为了更好地衡量,我将我的附加存储库放入settings.gradle,结果如下:

      dependencyResolutionManagement {
          repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) // WAS: FAIL_ON_PROJECT_REPOS
          repositories {
              google()
              mavenCentral()
              jcenter() // Warning: this repository is going to shut down soon
              maven {url 'https://mvnrepository.com'} // ADDED THIS
          }
      }
      

      进行这些更改后,Android Studio 标准构建过程会自动下载相应的工件。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-04-26
        • 2016-10-25
        • 1970-01-01
        • 1970-01-01
        • 2014-03-28
        • 2022-06-11
        • 2013-11-26
        • 2015-08-24
        相关资源
        最近更新 更多