我正在使用与 Android Studio bundle 的 Gradle 构建系统。到目前为止,我能够使用存储在我的项目结构中的依赖项来构建多项目设置。我现在想使用 Maven 依赖项,但无济于事。我写了一个非常简单的 build.gradle 文件,但总是失败:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile 'com.google.android:support-v4:r7'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
带有以下信息:
* What went wrong:
A problem occurred configuring project ':absabs'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':absabs:compile'.
> Could not find com.google.android:support-v4:r7.
Required by:
absabs:absabs:unspecified
....
Caused by: org.gradle.api.internal.artifacts.ivyservice.ModuleVersionNotFoundException: Could not find com.google.android:support-v4:r7.
到目前为止,我尝试过的任何 Artifact 都会发生这种情况。知道出了什么问题吗?
谢谢
最佳答案
buildscript 部分中的“repositories” block 仅适用于构建环境。您还需要指定在解析构建项目的依赖项时要使用的存储库,因此您需要在 build.gradle 文件中添加如下内容:
repositories {
mavenCentral()
}
您的完整文件将如下所示:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.android:support-v4:r7'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
注意“存储库”的两个实例。您可以在 the gradle docs 中阅读更多关于这实际上意味着什么的信息。 .
关于android - Maven 依赖与 Android Studio/Gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16671277/