将 Maven 存储库添加到 build.gradle [英] add maven repository to build.gradle

查看:51
本文介绍了将 Maven 存储库添加到 build.gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I added a custom maven repository to build.gradle in Android Studio but the dependency is not being found

Maven 存储库和依赖项

Maven repository and dependency

<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

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 中的错误消息:

Error message in 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 中缺少什么?

What am I missing in build.gradle?

推荐答案

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

You will need to define the repository outside of buildscript. The buildscript configuration block only sets up the repositories and dependencies for the classpath of your build script but not your application.

这篇关于将 Maven 存储库添加到 build.gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆