如何在Eclipse中包含Android gradle依赖项

时间:2013-10-05 05:30:27

标签: android eclipse android-gradle

我创建了简单的android eclipse项目。然后我添加了build.gradle文件。

buildscript {
  repositories {
    mavenCentral()
  }

  dependencies {
    classpath 'com.android.tools.build:gradle:0.4'
  }
}

task listJars << {
    configurations.compile.each { File file -> println file.path }
}

apply plugin: 'android'

android {
  compileSdkVersion 17
  buildToolsVersion '17'

  repositories {
    mavenCentral()
    }


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

    instrumentTest.setRoot('tests')
    instrumentTest {
      java.srcDirs = ['tests/src']
      res.srcDirs = ['tests/res']
      assets.srcDirs = ['tests/assets']
      resources.srcDirs = ['tests/src']
    }
  }

  dependencies {
    compile 'org.roboguice:roboguice:2.0' 
    compile fileTree(dir: 'libs', include: '*.jar')
  }
}

如您所见,我想从maven使用RoboGuice。 Gradle下载它,但不会添加到eclipse的lib文件夹中。所以我在编写代码时不能在eclipse中使用它。我需要手动复制它们吗?我添加了一个任务来显示它们:

$ gradle -q listJars
/Users/xxx/Documents/codepath2/SampleAndroidGradle/libs/android-support-v4.jar
/Users/xxx/.gradle/caches/artifacts-24/filestore/org.roboguice/roboguice/2.0/jar/727ccb8f376109d0b5c44abca6f791dccc5c5dbc/roboguice-2.0.jar
/Users/xxx/.gradle/caches/artifacts-24/filestore/javax.inject/javax.inject/1/jar/6975da39a7040257bd51d21a231b76c915872d38/javax.inject-1.jar
/Users/xxx/.gradle/caches/artifacts-24/filestore/aopalliance/aopalliance/1.0/jar/235ba8b489512805ac13a8f9ea77a1ca5ebe3e8/aopalliance-1.0.jar
/Users/xxx/.gradle/caches/artifacts-24/filestore/asm/asm/3.1/jar/c157def142714c544bdea2e6144645702adf7097/asm-3.1.jar
/Users/xxx/.gradle/caches/artifacts-24/filestore/org.sonatype.sisu.inject/cglib/2.2.1-v20090111/jar/7ce5e983fd0e6c78346f4c9cbfa39d83049dda2/cglib-2.2.1-v20090111.jar
/Users/xxx/.gradle/caches/artifacts-24/filestore/com.google.inject/guice/3.0/jar/28586dc97c525501329d9a242fc3402041e3572d/guice-3.0-no_aop.jar

2 个答案:

答案 0 :(得分:3)

这是正确的。 Gradle不会将jar放在lib目录中。假设您的lib目录用于手动更改jar。您可以创建一个Gradle任务,将它们复制到您的lib目录,如果这就是oyu想要做的事情。

我不认为eclipse中有gradle官方支持,如果你刚刚开始一个新项目,请考虑使用Android Studio(http://developer.android.com/sdk/installing/studio.html

答案 1 :(得分:1)

以下帖子包含两个Groovy片段,可以添加到build.gradle。它们中的任何一个都使Eclipse可以使用gradle依赖。

请参阅Add dependencies via gradle to eclipse in android project