繁体   English   中英

在Gradle中添加依赖项

[英]Adding dependencies in Gradle

我正在尝试将我的Android项目从IDEA迁移到带有Gradle的Android Studio。 但是,我在依赖方面遇到困难。 我删除了我的“ lib”目录,因此可以从maven中检索jar。 但是如何正确添加它们?

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

结果是:

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

它似乎在Maven仓库中。

您在最高级别上缺少此功能(即androiddependencies ):

repositories {
    mavenCentral()
}

buildscript块具有构建过程的 repositoriesdependencies 您还需要在顶层为项目本身的依赖项提供repositoriesdependencies

dependencies {
    compile 'org.apache.commons:commons-lang3:3.4'
}

在build.gradle文件中添加以上行,这是最新版本。

您也可以从这里检查它:

mvnrepository,Apache Commons Lang»3.4

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM