【问题标题】:Add Maven repository to build.gradle将 maven 存储库添加到 build.gradle
【发布时间】:2014-01-01 16:06:14
【问题描述】:

我在 Android Studio 中为 build.gradle 添加了一个自定义 maven 存储库,但没有找到依赖项

Maven 存储库和依赖项

<repository>
    <id>achartengine</id>
    <name>Public AChartEngine repository</name>
    <url>https://repository-achartengine.forge.cloudbees.com/snapshot/</url>
</repository>

<dependency>
    <groupId>org.achartengine</groupId>
    <artifactId>achartengine</artifactId>
    <version>1.2.0</version>
</dependency>

build.gradle

buildscript {
    repositories {
        mavenCentral()
        maven {
            url "https://repository-achartengine.forge.cloudbees.com/snapshot/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile group: 'org.achartengine', name: 'achartengine', version: '1.2.0'
}

android {
    compileSdkVersion 19
    buildToolsVersion "19"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

Android Studio 中的错误消息:

A problem occurred configuring root project 'My-MobileAndroid'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':_DebugCompile'.
  > Could not find org.achartengine:achartengine:1.2.0.
    Required by:
        :My-MobileAndroid:unspecified

我在 build.gradle 中缺少什么?

【问题讨论】:

    标签: android maven gradle android-studio achartengine


    【解决方案1】:

    之后

    apply plugin: 'com.android.application'
    

    你应该添加这个:

      repositories {
            mavenCentral()
            maven {
                url "https://repository-achartengine.forge.cloudbees.com/snapshot/"
            }
        }
    

    @Benjamin 解释了原因。

    如果你有一个带有身份验证的 maven,你可以使用:

    repositories {
                mavenCentral()
                maven {
                   credentials {
                       username xxx
                       password xxx
                   }
                   url    'http://mymaven/xxxx/repositories/releases/'
                }
    }
    

    顺序很重要。

    【讨论】:

    • 我们如何在gradle文件中添加cloudbees认证?
    • 如何修改Android Studio,让maven仓库默认添加到build.gradle。我一直忘记这一点,不得不重新发现库不加载的原因。
    【解决方案2】:

    您需要在buildscript 之外定义存储库。 buildscript 配置块仅设置构建脚本的类路径的存储库和依赖项,而不是您的应用程序。

    【讨论】:

    • 这对依赖项进行了排序,但 Android Studio 没有重新加载存储库,因此 "import org.achartengine.chart.*;"失败了,你知道如何“刷新”存储库吗?
    • 非常重要。在这个上浪费了 15 分钟
    • buildscript 内部和外部repositories 是否应该具有相同的远程存储库?
    【解决方案3】:

    Android Studio 用户:

    如果您想使用等级,请转到 http://search.maven.org/ 并搜索您的 maven 存储库。然后,单击“最新版本”,在左下方的详细信息页面中,您将看到“Gradle”,然后您可以将该链接复制/粘贴到您应用的 build.gradle 中。

    【讨论】:

    • 你让我很开心,非常感谢。另外,为什么这不在ZXing gh 官方页面中?应该不难找到...
    【解决方案4】:

    您必须将repositories 添加到您的构建文件中。对于 maven 存储库,您必须在存储库名称前加上 maven{}

    repositories {
      maven { url "http://maven.springframework.org/release" }
      maven { url "http://maven.restlet.org" }
      mavenCentral()
    }
    

    【讨论】:

      【解决方案5】:

      在您的主build.gradle 文件的buildscript 配置块之外添加maven 存储库,如下所示:

      repositories {
              maven {
                  url "https://github.com/jitsi/jitsi-maven-repository/raw/master/releases"
              }
          }
      

      确保在以下内容之后添加它们:

      apply plugin: 'com.android.application'
      

      【讨论】:

        猜你喜欢
        • 2019-04-30
        • 1970-01-01
        • 2015-04-26
        • 2014-08-22
        • 1970-01-01
        • 2014-11-22
        • 1970-01-01
        • 1970-01-01
        • 2014-03-28
        相关资源
        最近更新 更多