是否可以在 Eclipse 中使用 Android 的 Gradle 构建系统? [英] Is it possible to use the Gradle build system for Android with Eclipse?

查看:20
本文介绍了是否可以在 Eclipse 中使用 Android 的 Gradle 构建系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用需要针对不同的客户使用不同的资源(品牌、配置和客户之间的预加载数据更改)多次构建.

I've an app that needs to be build multiple times with different resources for different customers (branding, configuration, and pre-loaded data change between customers).

在今年的 Google I/O 之后,我听说了新的基于 Gradle 的 Android 构建系统.所以我想,使用 Gradle 构建脚本来实现这种单源/多 apk 场景是个好主意.

In the wake of this year's Google I/O I've heard about the new Gradle-based Android build-system. So I thought, it would be a good idea, to realize this one-source/multiple-apks scenario using a Gradle build script.

现在我的问题来了:如何在坚持使用 Eclipse 的同时开始使用 Gradle 进行构建?我在网上找到的所有内容都指向将项目转换为仍然不成熟的 Android Studio.我想推迟迁移到 Android Studio,直到 Google 宣布其安全"可用于生产.

Now here comes my question: How can I get started using Gradle for building while sticking to Eclipse? All the reads I found online point to converting the project to the still immature Android Studio. I'd like to put off migrating to Android Studio until that's declared "safe" for production use by Google.

理想情况下,我希望能够将构建脚本挂钩到 Eclipse 的调试和运行配置,这与我可以选择不同的构建目标以在 XCode 中进行调试和存档非常相似.如果可能,需要采取哪些步骤才能使其发挥作用?

Ideally, I'd like to be able to hook the build script(s) to the Debug and Run Configurations of Eclipse, very much the same way as I can pick and choose different build targets for debugging and archiving in XCode. If that's possible, what steps are required to make that work?

我为这些问题的愚蠢而道歉,但对我来说,这实际上是一个未被发现的国家.任何帮助表示赞赏.

I apologize for the noobish quality of these questions, but for me this is actually quite an undiscovered country. Any help is appreciated.

我们的团队已于 2013 年 10 月下旬迁移到 Android Studio,自 0.4 版以来,遇到的错误越来越少.如果您的组织对于采用 1.0 之前的环境进行开发不是非常保守,我鼓励您跳入冷水并尝试使用 Android Studio 及其 Gradle 构建系统.恕我直言,唯一缺少的是对单元测试的体面支持.

Our team has migrated to Android Studio in late October 2013 and since version 0.4 were are encountering fewer and fewer bugs. If your organization is not super-conservative about adopting pre-1.0 environments for development, I'd encourage you to jump into the cold water and try working with Android Studio and its Gradle build system. The only important thing missing IMHO is decent support for unit-testing.

推荐答案

可以使用 2 个构建系统(基于 Eclipse + gradle).只需确保输出文件夹不同(bin 用于 ADT,build 用于 gradle).(TL 更新;DR:检查 Nodeclipse/Enide Gradle日食(市场) )

It is possible to use 2 build systems (Eclipse + gradle based). Just make sure output folders are different (bin for ADT, build for gradle). (Update for TL;DR : check Nodeclipse/Enide Gradle for Eclipse (marketplace) )

文件 ->导出 ->生成 Gradle 构建文件 将只添加带有以下内容的 build.gradle(但请检查版本).没有更改现有文件.

File -> Export -> Generate Gradle build files will just add build.gradle with content below (but check versions). No existing files are changed.

com.android.tools.build:gradle 版本应该是 最新的.对于 中所说的 gradle 类型 gradle buildhttp://tools.android.com/tech-docs/new-build-system/user-guide.尝试 gradle tasks 了解更多信息.(在我缓慢的互联网连接上,gradle 下载了所有需要的依赖项花了 1 小时)

com.android.tools.build:gradle version should be the latest. For gradle type gradle build as said in http://tools.android.com/tech-docs/new-build-system/user-guide. Try gradle tasks for more. (On my slow Internet connection it took 1 hour! for gradle to download all needed dependencies)

Vogella 教程 http://www.vogella.com/articles/AndroidBuild/article.html 还没有准备好.其他网上教程都没有真正完成http:///www.jayway.com/2013/02/26/using-gradle-for-building-android-applications/

Vogella tutorial http://www.vogella.com/articles/AndroidBuild/article.html is not yet ready. Other online tutorials are not really finished http://www.jayway.com/2013/02/26/using-gradle-for-building-android-applications/

Eclipse ADT 还没有使用 gradle,我认为它会先在 Android Studio 中完善.在两个 IDE 中同时开始使用不断发展的技术是不明智的.

Eclipse ADT is not yet using gradle, I think it will be polished within Android Studio first. It would be not so wise to start using evolving technology in both IDEs at the same time.

参见下面的 build.gradle 示例.如果您已经掌握了 gradle,那么可能根本不需要 Wizards.对于经典 Android 项目的最新 build.gradle 模板,请查看 gh.c/N/n-1/b/m/oneeg/docs/android/build.gradle.

See build.gradle example below. If you already mastered gradle, then maybe Wizards is not needed at all. For the latest build.gradle template for classic Android project check gh.c/N/n-1/b/m/o.n.e.e.g/docs/android/build.gradle.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

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

android {
    compileSdkVersion 8
    buildToolsVersion "19.0.0"

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

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

Eclipse Marketplace 未附带 ADT-Bundle,因此可以使用更新站点.

ADT-Bundle does not come with Eclipse Marketplace, so update site could be used.

更新 Gradle Integration for Eclipse 的 p2 存储库是

Update p2 repository for Gradle Integration for Eclipse is

http://dist.springsource.com/release/TOOLS/gradle

但是从 3.4.0 版本开始,它不提供 .gradle 文件的编辑器.所以没有任何意义将其用于 Android 开发.

But as of version 3.4.0 it does not provide Editor for .gradle files. So there is no sense of having it for Android development.

我会使用默认的 ADT 构建,将 gradle 作为实验的辅助构建并密切关注 http://tools.android.com/上的错误流tech-docs/new-build-system 变得罕见.(应该是正式的1.0版本左右)

I would go with default ADT build, having gradle as secondary build for experimentations and keeping an eye when flow of bugs on http://tools.android.com/tech-docs/new-build-system becomes rare. (That should be around formal 1.0 version)

更新:2014-04-15

UPDATE: 2014-04-15

Alex Ruiz(来自 Android 团队)关于 Android、Gradle & 的博客ADT

我们决定使用与 IDE 无关的 Gradle 项目表示,而不是创建特定于 IDE 的 Android/Gradle 模型.这样,我们就有了更易于维护的单一信息源.IDE 集成将作为每个受支持 IDE(在我们的示例中为 Eclipse 和 IDEA)的插件来实现.这种方法的主要好处是我们可以独立于 IDE 集成插件发布 Gradle 插件.例如,我们可以发布一个新版本的 Eclipse 插件,该插件修复了几个错误,而不会影响 Android 的 Gradle 端.

Android’s Gradle Model

Instead of creating IDE-specific Android/Gradle models, we decided to have an IDE-agnostic representation of a Gradle project. This way, we have a single source of information that is easier to maintain. IDE integration will be implemented as a plug-in for each supported IDE (in our case, Eclipse and IDEA.) The main benefit of this approach is that we can release the Gradle plug-in independently of the IDE integration plug-ins. For example, we can ship a new version of the Eclipse plug-in that has several bug fixes, without affecting the Gradle side of Android.

截至 2014 年 4 月,eclipse-gradle 插件与 android-gradle 插件不兼容:

As of April 2014 eclipse-gradle plugin is not compatible with android-gradle plugin:

Android 团队在 问题 57668 中回答(提出来自@arcone)

As answered in Issue 57668 by Android team (raised by @arcone)

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

Project Member #2 x...@android.com

eclipse插件与android插件不兼容.

The eclipse plugin is not compatible with the android plugin.

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

You will not be able to import an Android gradle project into Eclipse using the default Gradle support in Eclipse.

为了让它在 Eclipse 中工作,我们必须为 Eclipse 更改 Gradle 插件,就像我们在 IntelliJ 中修改 Gradle 支持一样

To make it work in Eclipse we will have to change the Gradle plugin for Eclipse, the same way we are modifying the Gradle support in IntelliJ

Android 团队正在开发 IntelliJ 的 gradle 插件,Eclipse 的 gradle 插件也需要更新.

That is Android team is working on gradle plugin for IntelliJ and gradle plugin for Eclipse needs to be updated too.

Nodeclipse 正在努力来平滑过渡时间.并继续在 Eclipse 中进行开发,同时仍在试验或完全使用 gradle.

There is effort at Nodeclipse to smooth the transition times. And continue to develop in Eclipse while still experimenting or fully using gradle.

用于 Eclipse 的 Nodeclipse/Enide Gradle(市场)

Gradle for Eclipse 的一些屏幕截图:

Some screenshots for Gradle for Eclipse:

这篇关于是否可以在 Eclipse 中使用 Android 的 Gradle 构建系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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