gpt4 book ai didi

android - 是否可以在 Eclipse 中使用适用于 Android 的 Gradle 构建系统?

转载 作者:IT老高 更新时间:2023-10-28 22:22:12 25 4
gpt4 key购买 nike

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

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

现在我的问题来了:如何在坚持使用 Eclipse 的同时开始使用 Gradle 进行构建?我在网上找到的所有读物都指向将项目转换为仍然不成熟的 Android Studio。我想推迟迁移到 Android Studio,直到它被 Google 宣布为“安全”以供生产使用。

理想情况下,我希望能够将构建脚本与 Eclipse 的调试和运行配置 Hook ,这与我可以选择不同的构建目标以在 XCode 中进行调试和归档非常相似。如果可以的话,需要哪些步骤才能实现?

我为这些问题的无聊性质道歉,但对我来说,这实际上是一个未被发现的国家。任何帮助表示赞赏。

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

最佳答案

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

File -> Export -> Generate Gradle build files 只会添加 build.gradle 内容如下(但检查版本)。没有更改任何现有文件。

com.android.tools.build:gradle 版本应为 the latest .对于 gradle 类型 gradle buildhttp://tools.android.com/tech-docs/new-build-system/user-guide 中所述.尝试 gradle tasks 了解更多信息。 (在我缓慢的 Internet 连接上,需要 1 小时!gradle 下载所有需要的依赖项)

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

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

请参阅下面的 build.gradle 示例。如果你已经掌握了 gradle,那么可能根本不需要 Wizards。有关经典 Android 项目的最新 build.gradle 模板,请查看 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')
}
}

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

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

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

但从 3.4.0 版开始,它不提供 .gradle 文件的编辑器。所以在 Android 开发中使用它是没有意义的。

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

更新:2014-04-15

Alex Ruiz's (from Android team) Blog about Android, Gradle & ADT

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 插件不兼容:

正如 Issue 57668 中的回答由 Android 团队(由@arcone 提出)

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

The eclipse plugin is not compatible with the android plugin.

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

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 插件也需要更新。

effort at Nodeclipse平滑过渡时间。并继续在 Eclipse 中进行开发,同时仍在试验或完全使用 gradle。

Nodeclipse/Enide Gradle for Eclipse(marketplace)

Gradle for Eclipse 的一些截图:

关于android - 是否可以在 Eclipse 中使用适用于 Android 的 Gradle 构建系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17107014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com