android - 将 Maven 存储库添加到 build.gradle

标签 android maven gradle android-studio achartengine

我在 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 中缺少什么?

最佳答案

之后

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/'
            }
}

顺序很重要。

关于android - 将 Maven 存储库添加到 build.gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20574111/

相关文章:

java - 如何从 DatagramPacket 中检索字符串

Android OCR 应用程序 : Tesseract dictionary

javascript - 网站(HTML5、JavaScript)能否访问移动设备(android/iPhone)的联系人列表、SDCard 文件

java - 在 MANIFEST.MF 文件中找不到属性 'JCabi-Version'

带有 git 子模块的 Android Maven IntelliJ 项目

intellij-idea - 如何执行gradle任务

android - 关于如何打开现有 Android 应用程序的困惑

java maven项目结构重构

android - 动态添加dependsOn到gradle任务

java - Gradle:如何将Java项目 flavor 依赖资源包含到Android APK中?