将 Maven 存储库添加到 build.gradle

我在 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>

建造,分级

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

我错过了什么?

229293 次浏览

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

之后

apply plugin: 'com.android.application'

你应该加上这个:

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

@ 本杰明解释了原因。

如果您有一个具有身份验证的专家,您可以使用:

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

命令很重要。

Android Studio 用户:

如果你想使用的等级,去 http://search.maven.org/和搜索您的专家回购。然后,点击“最新版本”,在左下角的详细信息页面中,你会看到“ Gradle”,在那里你可以复制/粘贴这个链接到你的应用程序的 build.Gradle。

enter image description here

您必须将 repositories添加到您的构建文件中

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

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

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

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

apply plugin: 'com.android.application'

这是针对 Kotlin DSL(build.gradle.kts)的:

repositories {
mavenCentral()
maven("https://jitpack.io")
// OR another notation:
// maven {
//     url = uri("https://jitpack.io")
// }
}

您还可以将所有子项目的存储库声明集中到更新版本的 Gradle (Gradle 7.4)的 设置文件中:

dependencyResolutionManagement {
repositories {
mavenCentral()
maven("https://jitpack.io")
// OR another notation:
// maven {
//     url = uri("https://jitpack.io")
// }
}
}

请参阅 Gradle 的 这里的完整指南文档网站。