跳过 build.xml 的 Eclipse 验证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3941177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:11:45  来源:igfitidea点击:

Skip Eclipse validation of build.xml

javaandroideclipsevalidationant

提问by Javi

I've followed the steps given in the Android Developer Blogto generate a build.xml for building releases for an Android Application. I need to do a custom compiling so I have overwritten the target compile of the ant_rules_r3.xml as it is said in the generated build.xml.

我已经按照Android 开发人员博客中给出的步骤生成了 build.xml,用于为 Android 应用程序构建版本。我需要做一个自定义编译,所以我已经覆盖了 ant_rules_r3.xml 的目标编译,正如它在生成的 build.xml 中所说的那样。

 <target name="compile" depends="-resource-src, -aidl, -pre-compile" ...

The script works fine and generates the apk, but the problem is that Eclipse shows an error because it cannot find targets -resource-src, -aidland -pre-compile(which are loaded when executing the script but are not really present on the build.xml). As there are these errors I cannot work with the project in Eclipse.

该脚本工作正常,并生成APK,但问题是,Eclipse中显示一个错误,因为它无法找到目标-resource-src-aidl-pre-compile(在执行脚本时被加载,但没有真正出现在build.xml文件)。由于存在这些错误,我无法在 Eclipse 中处理该项目。

How can I skip the validation of this single file in Eclipse?

如何在 Eclipse 中跳过对这个单个文件的验证?

回答by kukudas

I do not know if you can do this for a single file but i think you can disable the validation within the eclipse preferences under Validation.

我不知道您是否可以对单个文件执行此操作,但我认为您可以在验证下的 eclipse 首选项中禁用验证。

回答by Pepster

Another workaround (less drastic than disable all validation/problem reporting): Go to Window->preferences->Ant->Problems tab. Add "build.xml" to the ignore list...

另一种解决方法(比禁用所有验证/问题报告更简单):转到 Window->preferences->Ant->Problems 选项卡。将“build.xml”添加到忽略列表中...

回答by Steve McDuff

I found 2 solutions that work for me :

我找到了 2 个对我有用的解决方案:

1 - The solution from kukudas above :

1 - 以上 kukudas 的解决方案:

How about this: under preferences ant -> editor in the tab Problems "Ignore all buildfile problems" ? You can set there a specific file too if i'm not mistaken. – kukudas Oct 15 '10 at 10:28

这个怎么样:在选项卡问题“忽略所有构建文件问题”中的首选项 ant -> 编辑器下?如果我没记错的话,你也可以在那里设置一个特定的文件。– kukudas 10 年 10 月 15 日,10:28

While it works, this solution is workspace specific and can be quite tedious if a user wants to keep Ant validation for a few files but ignore a large number of files.

虽然它有效,但此解决方案是特定于工作区的,如果用户想要保留对少数文件的 Ant 验证但忽略大量文件,则可能会非常乏味。

2 - Eclipse seems to validate ant files only when they are opened in an editor. Therefore, another solution involves never opening ant files that shouldn't be validated using eclipse. I managed to get rid of warnings by doing a file backup-delete-restore.

2 - Eclipse 似乎只有在编辑器中打开 ant 文件时才会验证它们。因此,另一个解决方案涉及永远不要打开不应使用 eclipse 进行验证的 ant 文件。我设法通过执行文件备份-删除-恢复来消除警告。

Ideally, ant validation should be done like all other XML validation so it may be configured at project level.

理想情况下,ant 验证应该像所有其他 XML 验证一样完成,以便它可以在项目级别进行配置。

回答by Anm

Kukudas's solution to "Ignore all buildfile problems" does solve the root problem.

Kukudas 对“忽略所有构建文件问题”的解决方案确实解决了根本问题。

However, Eclipse will still detect the buidl.xml as broken and will not allow Ant Builders to call the file. In fact, Eclipse will silently ignore such build steps in your project as if weren't there.

但是,Eclipse 仍会检测到 buidl.xml 已损坏,并且不允许 Ant Builders 调用该文件。事实上,Eclipse 会默默地忽略项目中的此类构建步骤,就好像不存在一样。

回答by Matt Wolfe

I have figured out a much better solution to the problem of eclipse not finding build targets from the imported/included projects. First of all, upgrade to the r14 sdk. Revision 14 uses only a build.xml file from the ${sdk.dir}/tools/ant directory

我已经找到了一个更好的解决方案来解决 eclipse 无法从导入/包含的项目中找到构建目标的问题。首先,升级到r14 sdk。修订版 14 仅使用 ${sdk.dir}/tools/ant 目录中的 build.xml 文件

At the bottom of the build.xml file within your own project, you'll see an import statement that looks like this:

在您自己的项目中 build.xml 文件的底部,您将看到如下所示的导入语句:

<import file="${sdk.dir}/tools/ant/build.xml"/>

Change this statement to

将此语句更改为

<import file="${sdk.dir}/tools/ant/build.xml" as="androidbuild" />

Then from your project, you can reference those target with

然后从您的项目中,您可以引用这些目标

<target name="compile" depends="androidbuild.-resource-src, androidbuild.-aidl, androidbuild.-pre-compile" />

Also note that now they have pre-compile/pre-build tasks that will be called before compiling. (checkout the full build.xml to see exactly when they are called). You can use these as hooks to do some work before compiling without overriding the original tasks.

另请注意,现在它们具有将在编译之前调用的预编译/预构建任务。(查看完整的 build.xml 以确切了解何时调用它们)。您可以在编译之前将它们用作钩子来完成一些工作,而无需覆盖原始任务。