2013-10-05 84 views
1

我已經創建了簡單的android eclipse項目。然後我添加了build.gradle文件。如何在Eclipse中包含Android gradle dependencies

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 

回答

3

這是正確的。 Gradle不會將jar放在lib目錄中。假設您的lib目錄是用於手動更改jar的。你可以創建一個Gradle任務,將它們複製到你的lib目錄下,如果這是你想做的事情。

我不認爲這是在Eclipse中gradle這個官方的支持,如果你剛開始一個新的項目,可以考慮使用Android的工作室(http://developer.android.com/sdk/installing/studio.html

相關問題