添加Maven仓库build.gradle
我添加了一个自定义的Maven仓库在Android Studio build.gradle,但依赖没有被发现
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中错过了什么?
您需要定义buildscript
之外的存储库。 buildscript
configuration块只设置构build脚本的类path的存储库和依赖关系,而不是你的应用程序。
后
apply plugin: 'com.android.application'
你应该添加这个:
repositories { mavenCentral() maven { url "https://repository-achartengine.forge.cloudbees.com/snapshot/" } }
本杰明解释了原因。
如果你有一个authenticationmaven你可以使用:
repositories { mavenCentral() maven { credentials { username xxx password xxx } url 'http://mymaven/xxxx/repositories/releases/' } }
这是重要的顺序。
Android Studio用户:
如果你想使用等级,请访问http://search.maven.org/并search你的maven回购。; 然后,点击“最新版本”,在左下angular的详细信息页面中,您将看到“Gradle”,然后将该链接复制/粘贴到应用程序的build.gradle中。
您必须将repositories
添加到您的构build文件。 对于maven版本库,你必须在maven{}
repositories { maven { url "http://maven.springframework.org/release" } maven { url "http://maven.restlet.org" } mavenCentral() }
在build.gradle
文件的buildscript
configuration块之外添加maven仓库,如下所示:
repositories { maven { url "https://github.com/jitsi/jitsi-maven-repository/raw/master/releases" } }
确保在下列之后添加它们:
apply plugin: 'com.android.application'