如何使用Gradle为Android项目生成Eclipse和Intellij项目文件 [英] How to use Gradle to generate Eclipse and Intellij project files for Android projects

查看:148
本文介绍了如何使用Gradle为Android项目生成Eclipse和Intellij项目文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Gradle为Android项目生成Eclipse和Intellij项目文件?



在maven中,我们将执行 mvn eclipse:eclipse 并且在PlayFramework中,我们将执行播放eclipsify 。 Gradle对Android项目有这个功能吗?



我已经安装了Gradle(1.6)和Android SDK Manager(22.0.1)解释here



这是我的build.gradle文件:

  buildscript {
存储库{
mavenCentral()
}
依赖关系{
classpath'com.android.tools.build:gradle:0.5.0'
}


应用插件:'android'
应用插件:'eclipse'

sourceCompatibility = 1.7
version ='1.0.2'

存储库{
mavenCentral()
}

依赖项{
编译fileTree(dir:'libs',include:'* .jar')
}

android {
buildToolsVersion17
compileSdkVersion 8
defaultConfig {
versionCode 1
ver sionName1.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项目。任何人都知道如何获得 Gradle 以创建 Android 特定 Eclipse 项目文件?



这是Gradle的优先功能吗?



- 更新 -



我确实相信这是一个问题。所以我已经发布到Android Tools小组 issue#57668 。请为他们为他们优先考虑问题:)



- 更新 -



看起来Android Tools小组正在研究这个问题。所以现在我已经转换为 Android Studio ,在那里我可以导入我的毕业生项目通过IDE依赖。

解决方案

Gradle本身是一个通用构建工具,它不是专门为Android创建的。



所有功能都使用插件启用。传统上,构建插件不会生成项目结构。这就是项目具体工具的工作。问题在于SDK中的当前 android 工具会生成旧类型的项目结构(蚂蚁构建)。新的项目结构只能通过Android Studio生成。



在Maven这样的工具中有一个 archetypes 的概念,允许使用项目模板。 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的。


Is it possible to generate Eclipse and Intellij project files for Android projects using Gradle?

In maven we would do mvn eclipse:eclipse and in PlayFramework we would do play eclipsify. Does Gradle have this feature for Android projects?

I have installed Gradle (1.6) and Android SDK Manager (22.0.1) explained here

This is my build.gradle file:

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

And then I run the command:

gradle clean build cleanEclipse eclipse

It builds just fine, but when I import the project into Eclipse it looks like a normal java project.

Anyone know how to get Gradle to create Android specific Eclipse project files?

Is this a prioritized feature by Gradle?

-- UPDATE --

I do believe this is an issue. So I have posted it to the Android Tools team issue #57668. Please star it for them to prioritize the issue :)

-- UPDATE --

It does not look like the Android Tools team are looking into this issue. So for now I have converted to Android Studio where I'm able to import my gradle project with dependencies via the IDE.

解决方案

Gradle itself is a generic build tool, it is not created specifically for Android.

All the functionality is enabled using plug-ins. Traditionally, build plug-ins don't generate project structure. That's the job of project specific tools. The android plug-in for Gradle follows this.

The problem is that current android tool in SDK generates old type of project structure (ant builds). The new project structure can only be generated via Android Studio.

There is a concept of archetypes in tools like Maven, which allow using project templates. Gradle does not support that yet (requests have been made for this feature).

Refer to this thread: http://issues.gradle.org/browse/GRADLE-1289 , some users have provided scripts to generate structure.

Build Initialization feature is in progress: https://github.com/gradle/gradle/blob/master/design-docs/build-initialisation.md

Hopefully some one can write a script to do that, refer to this guide for new project structure: http://tools.android.com/tech-docs/new-build-system/user-guide

Update

There is now an official android IDE : Android Studio . It is based on Intellij and the new build system is Gradle based.

这篇关于如何使用Gradle为Android项目生成Eclipse和Intellij项目文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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