如何使用Gradle为Android项目生成Eclipse和Intellij项目文件

问题描述 投票:34回答:6

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

在maven我们会做qazxsw poi,在Play Framework中我们会做qazxsw poi。 Gradle是否为Android项目提供此功能?

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

这是我的build.gradle文件:

play eclipsify

然后我运行命令:

here

它构建得很好,但是当我将项目导入Eclipse时,它看起来像一个普通的java项目。

任何人都知道如何让Gradle创建Android特定的Eclipse项目文件?

这是Gradle的优先功能吗?

- 更新 -

我确实相信这是一个问题。所以我把它发布到Android工具团队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') } } 。请明星为他们优先解决问题:)

- 更新 -

它似乎不像Android工具团队正在调查此问题。所以现在我已经转换为gradle clean build cleanEclipse eclipse ,我可以通过IDE导入我的gradle项目与依赖项。

android eclipse ide intellij-idea gradle
6个回答
9
投票

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

使用插件启用所有功能。传统上,构建插件不会生成项目结构。这是项目特定工具的工作。 Gradle的android插件如下。

问题是SDK中的当前issue #57668工具生成旧类型的项目结构(ant构建)。新项目结构只能通过Android Studio生成。

在像Maven这样的工具中有一个Android Studio的概念,允许使用项目模板。 Gradle尚不支持(已针对此功能提出请求)。

请参阅此主题:android,一些用户提供了生成结构的脚本。

构建初始化功能正在进行中:archetypes

希望有人可以编写一个脚本来执行此操作,请参阅本指南以了解新项目结构:http://issues.gradle.org/browse/GRADLE-1289

更新

现在有一个官方的Android IDE:https://github.com/gradle/gradle/blob/master/design-docs/build-initialisation.md。它基于Intellij,新的构建系统基于Gradle。


3
投票

Gradle插件'com.android.application'和'eclipse'的组合有四个问题:首先,配置类路径没有添加到Eclipse的类路径中,但这很容易修复。其次,必须对.AAR依赖关系做些什么。这有点棘手。第三,我们需要包含像R.java这样的生成源。最后,我们需要包含Android.jar本身。

我能够破解一个gradle配置,它可以从Android Studio http://tools.android.com/tech-docs/new-build-system/user-guide为Eclipse生成适当的Android Studio文件。我的CPU风扇效果非常令人满意,它一直在Android Studio上运行。 Eclipse将生成的项目视为一个功能齐全的Java项目,但仅限于此。

我最终将以下内容直接放在我的app-project中的build.gradle中:

.classpath

运行build.config,您将拥有一个可以导入和编译的Eclipse项目。但是,此项目充当普通的Java项目。为了构建apk,我必须回到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获取Android XML文件中的更改并重新生成gradle installDebug下的文件。我使用Android SDK的“监视器”程序来查看应用程序日志。到目前为止,我没有找到任何方法来调试没有Android Studio。

我想念Android Studio的唯一功能是调试(但是谁有时间查看错误!)并直观地编辑资源。


2
投票

正如Android团队在gradle processDebugResources所回答的那样(由@arcone提出)

项目成员#2 x ... @ android.com

eclipse插件与android插件不兼容。

您将无法使用Eclipse中的默认Gradle支持将Android gradle项目导入Eclipse。

为了使它在Eclipse中运行,我们将不得不更改Eclipse的Gradle插件,就像我们在IntelliJ中修改Gradle支持一样

那就是Android团队正在开发IntelliJ的gradle插件,Eclipse的gradle插件也需要更新。

现在Eclipse的可能性是什么

0.1。将项目导入为一般项目

build/generated/source

Issue 57668

0.2。放2个Eclipse。 “点”文件到.project<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>OpenSpritz-Android</name> <comment></comment> <projects> </projects> <buildSpec> </buildSpec> <natures> </natures> </projectDescription> 模块

/OpenSpritz-Android/app/src/main

/OpenSpritz-Android/lib/src/main

.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>

0.3。作为现有Android代码导入Workspace

然后,您可以以熟悉的方式浏览代码,但即使在此之后,您也无法使用Eclipse ADT运行。

.4.

现在,您可以使用.classpath CLI或<?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> gradle)运行构建和任务

Nodeclipse/Enide Gradle for Eclipse讨论


2
投票

以下对我有用

marketplace

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

样本 - 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' }


2
投票

我已经创建了一个新的Gradle插件,它根据Johannes Brodwall在这个堆栈溢出时提供的答案生成相应的Eclipse http://blog.gouline.net/2013/11/02/new-build-system-for-android-with-eclipse/https://github.com/krishnaraj/oneclipboard文件。

有关详细信息,请参阅.project


1
投票

也许我错过了一些非常明显的东西,但不是.classpath你在寻找什么?这将生成.project文件以及.classpath文件,并在后续运行时根据需要更新这些文件。

还有一个https://github.com/greensopinion/gradle-android-eclipse,虽然我没有使用过这个并且不能说话。

希望有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.