2013-07-04 93 views
32

是否有可能產生使用搖籃的Android項目的Eclipse和IntelliJ項目文件?如何使用搖籃生成的Eclipse和IntelliJ項目文件的Android項目

Maven中,我們會做mvn eclipse:eclipse和PlayFramework我們會做play eclipsify。 Gradle是否爲Android項目提供此功能?

我已經安裝了搖籃(1.6)和Android SDK管理器(22.0.1)解釋here

這是我的build.gradle文件:

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:0.5.0' 
    } 
} 

apply plugin: 'android' 
apply plugin: 'eclipse' 

sourceCompatibility = 1.7 
version = '1.0.2' 

repositories { 
    mavenCentral() 
} 

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

android { 
    buildToolsVersion "17" 
    compileSdkVersion 8 
    defaultConfig { 
     versionCode 1 
     versionName "1.0" 
     minSdkVersion 7 
     targetSdkVersion 8 
    } 
    sourceSets { 
     main { 
       manifest.srcFile 'AndroidManifest.xml' 
       java.srcDirs = ['src'] 
       resources.srcDirs = ['src'] 
       aidl.srcDirs = ['src'] 
       renderscript.srcDirs = ['src'] 
       res.srcDirs = ['res'] 
       assets.srcDirs = ['assets'] 
     } 
     instrumentTest.setRoot('tests') 
    } 
} 

然後我運行命令:

gradle clean build cleanEclipse eclipse 

它建立得很好,但是當我將項目導入Eclipse中,它看起來像一個正常的Java項目。

任何人都知道如何得到搖籃創建的Android具體的Eclipse項目文件?

這是Gradle的優先功能嗎?

- 更新 -

我相信這是一個問題。所以我已將它發佈到Android工具團隊issue #57668。請明星爲他們的問題:)

優先 - 更新 -

它看起來並不像Android的工具團隊正在調查這個問題。所以現在我已經轉換爲Android Studio,我可以通過IDE導入帶有依賴關係的我的gradle項目。

+1

我相當肯定你不能(很容易)。我認爲我的目標是讓Eclipse ADT直接理解build.gradle,但恐怕這仍然是未來。 – Delyan

+0

你知道爲什麼這不是一個優先功能嗎?事件更好,你知道要聯繫誰來獲得這個功能嗎? –

+1

我不知道更多關於他們的優先級的內容,而不是[此列表]上的內容(http://tools.android。COM /路線圖)。也就是說,你最好的選擇是去['adt-dev'郵件列表](https://groups.google.com/forum/#!forum/adt-dev)並且在那裏詢問(不過首先搜索! )。 – Delyan

回答

9

Gradle本身是一個通用的構建工具,它不是專門爲Android創建的。

使用插件啓用所有功能。傳統上,構建插件不會生成項目結構。這是項目特定工具的工作。 Gradle的Android插件遵循這一點。

的問題是,在SDK當前android工具生成舊類型的項目結構的(螞蟻構建)。新的項目結構只能通過Android Studio生成。

還有就是archetypes像Maven的工具,使用項目模板,允許一個概念。 Gradle目前還不支持此功能(請求已經提供)。

請參閱此主題:http://issues.gradle.org/browse/GRADLE-1289,一些用戶已經提供的腳本生成的結構。

生成初始化功能正在進行中:https://github.com/gradle/gradle/blob/master/design-docs/build-initialisation.md

希望有一個人可以寫一個腳本來做到這一點,請參閱本指南爲新項目結構:http://tools.android.com/tech-docs/new-build-system/user-guide

更新

有現在是官方的Android IDE:Android Studio。它基於Intellij,新的構建系統是基於Gradle的。

+0

我不是在尋找Gradle的方式來創建'archetypes'。我所追求的是特定於IDE的項目文件的生成,它使我可以在我的首選IDE中導入爲項目。在maven中,我們將執行'mvn eclipse:eclipse',並且在Play Framework中,我們將執行'玩eclipsify'。我給了+1以便開始討論;) –

+0

@arcone啊..我不知道這裏有這樣一個插件。不支持導入Gradle項目的Eclipse嗎? –

+2

我已經安裝了Eclipse的Gradle插件,它似乎沒有工作。我應該補充一點,我沒有嘗試過這麼多,因爲我不想額外的複雜性。我肯定會喜歡有一個'gradle eclipse'命令來處理Android項目:) –

1

也許我錯過了一些非常明顯的東西,但不是eclipse plugin你在找什麼?這會生成.project文件以及.classpath文件,並在運行後續時間時根據需要更新這些文件。

還有一個IDEA plugin,雖然我沒有用過這個,也不能說話。

希望有所幫助。

+3

至於我所瞭解的gradle eclipse插件只生成java項目文件而不是Android :-( –

+0

啊,那將是明顯的一塊我但是可能是一個很好的起點 – Myles

2

正如Android團隊(由@arcone提出)

項目成員#2×... @ android.com

Eclipse插件是無法與Android插件兼容的Issue 57668回答。

您將無法使用Eclipse中默認的Gradle支持將Android gradle項目導入Eclipse。

,使其在Eclipse的工作,我們將不得不改變搖籃的Eclipse插件,同樣的道理,我們在的IntelliJ修改搖籃支持

即Android團隊正在gradle這個插件的IntelliJ和Eclipse的gradle插件也需要更新。

Eclipse現在有什麼可能是

.1。導入項目一般項目

.project

<?xml version="1.0" encoding="UTF-8"?> 
<projectDescription> 
    <name>OpenSpritz-Android</name> 
    <comment></comment> 
    <projects> 
    </projects> 
    <buildSpec> 
    </buildSpec> 
    <natures> 
    </natures> 
</projectDescription> 

import-android-gradle-as-general-project

0.2。放2 Eclipse。 「點」 文件到模塊到/OpenSpritz-Android/app/src/main/OpenSpritz-Android/lib/src/main

add-eclipse-files

.project

<?xml version="1.0" encoding="UTF-8"?> 
<projectDescription> 
    <name>OpenSpritz-Android-app</name> 
    <comment></comment> 
    <projects> 
    </projects> 
    <buildSpec> 
     <buildCommand> 
      <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> 
      <arguments> 
      </arguments> 
     </buildCommand> 
     <buildCommand> 
      <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> 
      <arguments> 
      </arguments> 
     </buildCommand> 
     <buildCommand> 
      <name>org.eclipse.jdt.core.javabuilder</name> 
      <arguments> 
      </arguments> 
     </buildCommand> 
     <buildCommand> 
      <name>com.android.ide.eclipse.adt.ApkBuilder</name> 
      <arguments> 
      </arguments> 
     </buildCommand> 
    </buildSpec> 
    <natures> 
     <nature>com.android.ide.eclipse.adt.AndroidNature</nature> 
     <nature>org.eclipse.jdt.core.javanature</nature> 
    </natures> 
</projectDescription> 

.classpath

<?xml version="1.0" encoding="UTF-8"?> 
<classpath> 
    <classpathentry kind="src" path="java"/> 
    <classpathentry kind="src" path="gen"/> 
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> 
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> 
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> 
    <classpathentry kind="output" path="bin/classes"/> 
</classpath> 

0.3。導入爲現有的Android代碼到工作區

results

你就可以瀏覽代碼熟悉的方式,但 甚至後,你將無法使用Eclipse ADT運行。

.4。

現在你可以用gradle CLI或Nodeclipse/Enide Gradle for Eclipsemarketplace)上運行的構建和任務

start

https://github.com/Nodeclipse/nodeclipse-1/issues/148

2

討論以下爲我工作

eclipse.classpath.plusConfigurations += configurations.compile 

eclipse.classpath.file { 
    beforeMerged { classpath -> 
    classpath.entries.removeAll() { c -> 
     c.kind == 'src' 
    } 
} 

withXml { 
    def node = it.asNode() 

    node.appendNode('classpathentry kind="src" path="src/main/java"') 
    node.appendNode('classpathentry kind="src" path="src/debug/java"') 
    node.appendNode('classpathentry kind="src" path="gen"') 

    node.children().removeAll() { c -> 
     def path = c.attribute('path') 
     path != null && (
       path.contains('/com.android.support/support-v4') 
       ) 
    } 
    } 
} 

eclipse.project { 
    name = 'AndroidGradleBasic' 

    natures 'com.android.ide.eclipse.adt.AndroidNature' 
    buildCommand 'com.android.ide.eclipse.adt.ResourceManagerBuilder' 
    buildCommand 'com.android.ide.eclipse.adt.PreCompilerBuilder' 
    buildCommand 'com.android.ide.eclipse.adt.ApkBuilder' 
} 

來源 - http://blog.gouline.net/2013/11/02/new-build-system-for-android-with-eclipse/

樣本 - https://github.com/krishnaraj/oneclipboard

2

有四個問題與搖籃插件「com.android.application」和「月食」的組合:一是不添加配置類路徑Eclipse的類路徑,但這是易於修復。其次,必須對.AAR依賴性做些事情。這有點棘手。第三,我們需要包含像R.java這樣的東西的生成源。最後,我們需要包含Android.jar本身。

我能夠一起構建一個gradle配置,從Android Studio build.config中爲Eclipse生成適當的.classpath文件。我的CPU風扇的效果非常令人滿意,這款風扇一直在Android Studio上運行。 Eclipse將生成的項目視爲一個功能完整的Java項目,但僅此而已。

我最後決定將直接在我的應用程序項目的build.gradle如下:

apply plugin: 'eclipse' 
eclipse { 
    pathVariables 'GRADLE_HOME': gradle.gradleUserHomeDir, "ANDROID_HOME": android.sdkDirectory 
    classpath { 
     plusConfigurations += [ configurations.compile, configurations.testCompile ] 

     file { 
      beforeMerged { classpath -> 
       classpath.entries.add(new org.gradle.plugins.ide.eclipse.model.SourceFolder("src/main/java", "bin")) 
       // Hardcoded to use debug configuration 
       classpath.entries.add(new org.gradle.plugins.ide.eclipse.model.SourceFolder("build/generated/source/r/debug", "bin")) 
       classpath.entries.add(new org.gradle.plugins.ide.eclipse.model.SourceFolder("build/generated/source/buildConfig/debug", "bin")) 
      } 

      whenMerged { classpath -> 
       def aars = [] 
       classpath.entries.each { dep -> 
        if (dep.path.toString().endsWith(".aar")) { 
         def explodedDir = new File(projectDir, "build/intermediates/exploded-aar/" + dep.moduleVersion.group + "/" + dep.moduleVersion.name + "/" + dep.moduleVersion.version + "/jars/") 
         if (explodedDir.exists()) { 
          explodedDir.eachFileRecurse(groovy.io.FileType.FILES) { 
           if (it.getName().endsWith("jar")) { 
            def aarJar = new org.gradle.plugins.ide.eclipse.model.Library(fileReferenceFactory.fromFile(it)) 
            aarJar.sourcePath = dep.sourcePath 
            aars.add(aarJar) 
           } 
          } 
         } else { 
          println "Warning: Missing " + explodedDir 
         } 
        } 
       } 
       classpath.entries.removeAll { it.path.endsWith(".aar") } 
       classpath.entries.addAll(aars) 

       def androidJar = new org.gradle.plugins.ide.eclipse.model.Variable(
        fileReferenceFactory.fromPath("ANDROID_HOME/platforms/" + android.compileSdkVersion + "/android.jar")) 
       androidJar.sourcePath = fileReferenceFactory.fromPath("ANDROID_HOME/sources/" + android.compileSdkVersion) 
       classpath.entries.add(androidJar) 
      } 
     } 
    } 
} 

// We need build/generated/source/{r,buildConfig}/debug to be present before generating classpath 
// This also ensures that AARs are exploded 
eclipseClasspath.dependsOn "generateDebugSources" 


// Bonus: start the app directly on the device with "gradle startDebug" 
task startDebug(dependsOn: "installDebug") << { 
    exec { 
     executable = new File(android.sdkDirectory, 'platform-tools/adb') 
     args = ['shell', 'am', 'start', '-n', android.defaultConfig.applicationId + '/.MainActivity'] 
    } 
} 

運行gradle eclipse,你將有一個Eclipse項目可以導入和編譯。但是,這個項目是一個普通的Java項目。爲了構建apk,我必須退回到gradle命令行並執行gradle installDebuggradle processDebugResources接收Android XML文件中的更改並重新生成build/generated/source下的文件。我使用Android SDK的「監視器」程序查看應用程序日誌。如果沒有Android Studio,我目前還沒有找到任何方法來進行調試。

我從Android Studio中錯過的唯一功能是調試(但誰有時間處理錯誤!)並以可視方式編輯資源。

+1

這對我來說非常合適,我已經創建了一個Gradle插件來完成這個工作,稍作修改以適應全新的Android構建系統https://github.com/greensopinion/gradle-android-eclipse –

+0

這個工作,我需要一些幫助,將這個項目轉換爲eclipse庫。任何想法呢? – Govind