Android 将 Maven 存储库添加到 build.gradle
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20574111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
add maven repository to build.gradle
提问by André Ricardo
I added a custom maven repository to build.gradle in Android Studio but the dependency is not being found
我在 Android Studio 中向 build.gradle 添加了一个自定义 Maven 存储库,但未找到依赖项
Maven repository and dependency
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
构建.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')
}
}
Error message in Android Studio:
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
What am I missing in build.gradle?
我在 build.gradle 中缺少什么?
采纳答案by Benjamin Muschko
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.
您将需要在buildscript
. 该buildscript
配置仅阻止树立库和依赖关系构建脚本的类路径,但不是你的应用程序。
回答by Gabriele Mariotti
After
后
apply plugin: 'com.android.application'
You should add this:
你应该添加这个:
repositories {
mavenCentral()
maven {
url "https://repository-achartengine.forge.cloudbees.com/snapshot/"
}
}
@Benjamin explained the reason.
@Benjamin 解释了原因。
If you have a maven with authentication you can use:
如果您有带身份验证的 Maven,您可以使用:
repositories {
mavenCentral()
maven {
credentials {
username xxx
password xxx
}
url 'http://mymaven/xxxx/repositories/releases/'
}
}
It is important the order.
顺序很重要。
回答by Micro
Android Studio Users:
安卓工作室用户:
If you want to use grade, go to http://search.maven.org/and search for your maven repo. Then, click on the "latest version" and in the details page on the bottom left you will see "Gradle" where you can then copy/paste that link into your app's build.gradle.
如果您想使用 Grade,请访问http://search.maven.org/并搜索您的 maven 存储库。然后,单击“最新版本”,在左下角的详细信息页面中,您将看到“Gradle”,然后您可以将该链接复制/粘贴到您的应用程序的 build.gradle 中。
回答by Marcin Szymczak
You have to add repositories
to your build file. For maven repositories you have to prefix repository name with maven{}
你必须添加repositories
到你的构建文件中。对于 Maven 存储库,您必须在存储库名称前加上maven{}
repositories {
maven { url "http://maven.springframework.org/release" }
maven { url "http://maven.restlet.org" }
mavenCentral()
}
回答by Kasumi Gunasekara
Add the maven repository outside the buildscript
configuration block of your main build.gradle
file as follows:
buildscript
在主build.gradle
文件的配置块之外添加 maven 存储库,如下所示:
repositories {
maven {
url "https://github.com/jitsi/jitsi-maven-repository/raw/master/releases"
}
}
Make sure that you add them after the following:
确保在以下内容之后添加它们:
apply plugin: 'com.android.application'