建立在Eclipse多SDK的Andr​​oid应用程序,而不会失去编译时检查 [英] Building multi-SDK Android apps in Eclipse without losing compile-time checks

查看:140
本文介绍了建立在Eclipse多SDK的Andr​​oid应用程序,而不会失去编译时检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发在Eclipse中的Andr​​oid应用程序。我想针对各种设备和SDK版本(例如,我可以有选择地支持多点触控)的。我理解的<一个href=\"http://android-developers.blogspot.com/2010/07/how-to-have-your-cupcake-and-eat-it-too.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+blogspot%2FhsDu+%28Android+Developers+Blog%29\">recommended接近隔离所有新功能,以一个单独的类,并利用延迟加载仅如果主机设备实际支持该功能加载类在运行时。

I am developing an Android app in Eclipse. I would like to target a wide variety of devices and SDK versions (for example, I can optionally support multi-touch). I understand the recommended approach of isolating all the new functionality to a separate class and leveraging lazy loading to only load that class at run-time if the host device actually supports the feature.

这种方法的缺点是,我必须编译所有的code与最新的功能,我想使用的SDK。如果一些新特性泄漏到我的版本中性code,这意味着,编译器不再能抓住它。

The downside of this approach is that I have to compile all of my code with the SDK of the newest feature I want to use. Which means if some new feature leaks into my "version neutral" code, the compiler can no longer catch it.

我想的能力,在Eclipse中,编译我的项目针对较旧的Andr​​oid SDK,以确保我的版本中性code是罚款。我想,以避免移动我的构建系统出来的Eclipse,如果可能的话。我没事这个老SDK构建是一个有点尴尬运行。

I would like the ability, within Eclipse, to compile my project against an older Android SDK to make sure my "version neutral" code is fine. I'd like to avoid moving my build system out of Eclipse, if possible. I'm okay with this old-SDK build being a bit awkward to run.

我认为这归结为做Eclipse内部一些有条件的compliation(或有条件的链接)?例如,在我的项目建设对SDK-1.6的时候,我想离开MultiTouchHandler.java源出构建。我不知道如果可能EX preSS生成类型像这样在Eclipse中,虽然。

I think this boils down to doing some conditional compliation (or conditional "linking") inside Eclipse? For example, in my project when building against SDK-1.6 I'd like to leave the "MultiTouchHandler.java" source out of the build. I'm not sure if its possible to express "build types" like this in Eclipse, though.

本哈克的解决方案似乎只是手动更改项目的SDK版本,改造,并通过错误看,而忽略了预期的错误。该解决方案矫枉过正好像是写我自己的蚂蚁/ Maven的/使构建脚本。

The hacky solution seem to be just manually changing the project's SDK version, rebuilding, and looking through the errors, and ignore 'expected' errors. The overkill solution seems to be writing my own ant/maven/make build scripts.

这个问题:
<一href=\"http://stackoverflow.com/questions/3706512/versioning-and-common-$c$c-bases-with-eclipse\">Versioning共同code-基地与Eclipse
涵盖了类似的理由,但是将涉及所有版本特定的类移动到单独的库。 (我仍然会在Eclipse中多个构建类型的问题,我想。)

This question: Versioning and common code-bases with Eclipse covers similar ground, but would involve moving all of the version-specific classes into separate "libraries". (And I would still have the problem of multiple build types in Eclipse, I think.)

这个问题:
<一href=\"http://stackoverflow.com/questions/1367077/build-multiple-project-configurations-with-eclipse\">Build与Eclipse 多个项目配置意味着我应该移动到外部的构建系统(如Ant或Maven),但是这不只是一个老SDK从时间努力构建时间很多工作。

This question: Build multiple project configurations with eclipse implies that I should move to an external build system (like ant or maven), but that's a lot more work than just trying a build with an old SDK from time to time.

推荐答案

2012年2月(V17)更新到皮棉工具在ADT应该帮助解决这个无需多建。当一个应用程序针对一个老的最低SDK,但对最新的SDK编译(因为是推荐的做法),如果被调用到新的SDK调用皮棉工具将另行通知。如果您确信调用的是好(因为你已经隐藏它运行时SDK_INT检查,或任何后面),你可以速战速决的注释,以prevent警告。

The February 2012 (v17) updates to the Lint Tool in the ADT should help address this without requiring multiple builds. When an app targets an old minimum SDK, but is compiled against the newest SDK (as is the recommended practice), the lint tool will notice if calls to the newer SDK are invoked. If you're confident the call is okay (Because you've hidden it behind a run-time SDK_INT check, or whatever), you can Quick-Fix an annotation to prevent the warning.

例如,在我的code我要View.setSystemUiVisibility一个电话,这是在11 API引入了,但我打靶API 8.运行皮棉所示:

For example, in my code I have a call to View.setSystemUiVisibility, which was introduced in API 11, but I'm targetting API 8. Running Lint shows:

呼叫API需要11级(当前分钟为8):android.view.View#setSystemuiVisibility

Call requires API level 11 (current min is 8): android.view.View#setSystemuiVisibility

该QuickFix的建议2种修复,要么补充说SUP presses警告或添加声明code的一大块​​作为API 11个工作注释注解。

The QuickFix suggests two kinds of fixes, either adding an annotation that suppresses the warning or adding an annotation that declares a chunk of code as working at API 11.

更多细节: http://tool​​s.android.com/recent/lintapicheck

这篇关于建立在Eclipse多SDK的Andr​​oid应用程序,而不会失去编译时检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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