在Gradle中添加依赖关系 [英] Adding dependencies in Gradle

查看:812
本文介绍了在Gradle中添加依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试将我的Android项目IDEA移至带有Gradle的Android Studio。
但是,我对依赖关系有困难。我删除了我的lib目录,所以jar将从maven中检索。但如何正确添加它们?



例如, org.apache.commons.lang3

  buildscript {
知识库{
mavenCentral()
}
dependencies {
classpath'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin:'android'

依赖关系{
编译'com.google.android.gms:play-services:4.1。+'
compile'org.apache.commons:commons-lang3:2.6。+'
}

android {
compileSdkVersion 19
buildToolsVersion19.0.1

sourceSets {
main {
manifest.srcFile'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}

/ /将测试移动到测试/ java,测试/资源等...
instrumentTest.setRoot('tests')

//将构建类型移至构建类型/< type>
//例如,build-types / debug / java,build-types / debug / AndroidManifest.xml,...
//将它们移出它们在src /< type>下的默认位置; / ...
//与主源集合使用的src /有冲突。
//添加新的构建类型或产品风格应该伴随
//通过类似的定制。
debug.setRoot('build-types / debug')
release.setRoot('build-types / release')
}
}


$ b

结果如下:

 失败刷新Gradle项目'idoms-android'
无法找到commons:commons-lang3:3.0。

虽然它似乎位于Maven Repository中。

android 和依赖关系

 存储库{
mavenCentral()
}

buildscript 块有版本库构建过程依赖关系。您还需要顶层的存储库依赖关系来获得项目本身的依赖关系。


I am trying to move my Android project form IDEA to Android Studio with Gradle. However, I am having difficulties with the dependencies. I removed my "lib" dir, so the jars would be retrieved from maven. But how do I correctly add them?

E.g. org.apache.commons.lang3

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}
apply plugin: 'android'

dependencies {
    compile 'com.google.android.gms:play-services:4.1.+'
    compile 'org.apache.commons:commons-lang3:2.6.+'
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

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

This results in:

Failed to refresh Gradle project 'idoms-android'
         Could not find commons:commons-lang3:3.0.

It seems to be in the Maven Repository though.

解决方案

You are missing this at the top level (i.e., a peer of android and dependencies):

repositories {
    mavenCentral()
}

The buildscript block has repositories and dependencies for the build process. You also need repositories and dependencies at the top level for the dependencies for your project itself.

这篇关于在Gradle中添加依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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