Maven依赖与Android工作室/摇篮 [英] Maven Dependencies with Android Studio / Gradle

查看:203
本文介绍了Maven依赖与Android工作室/摇篮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用捆绑的Andr​​oid Studio中的摇篮构建系统。到目前为止,我能够生成使用存储在我的项目结构相关性多项目的设置。我现在想用一个maven的依赖,但没有成功。我写了一个总是失败一个非常简单的build.gradle文件:

I am using the Gradle build system bundled with Android Studio. So far, I am able to build multi-project setups using dependencies that are stored in my project structure. I would now like to use a maven dependency, to no avail. I have written a very simple build.gradle file that always fails :

    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.

这发生在我已经试过到目前为止任何神器。有什么不对任何想法?

It happens with any artifact I have tried so far. Any idea of what's wrong ?

感谢

推荐答案

在buildscript节中的库块只适用于构建环境。您还需要指定用于构建项目解决相关性问题时要使用哪个版本库,所以你需要把类似的东西在你的build.gradle文件中的以下内容:

The "repositories" block in the buildscript section only applies to the build environment. You also need to specify which repository to use when resolving dependencies for building your project, so you need to put something like the following in your build.gradle file:

repositories {
    mavenCentral()
}

您完整的文件看起来是这样的:

Your complete file would look something like this:

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

请注意库的两个实例。你可以阅读更多关于这实际上意味着的摇篮文档

Note the two instances of "repositories". You can read more about what this actually means in the gradle docs.

这篇关于Maven依赖与Android工作室/摇篮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆