在Eclipse中构建多SDK SDK应用程序,而不会丢失编译时检查 [英] Building multi-SDK Android apps in Eclipse without losing compile-time checks

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

问题描述

我正在Eclipse中开发一个Android应用程序。我想要针对各种设备和SDK版本(例如,我可以选择支持多点触控)。我了解推荐方法将所有新功能隔离到一个单独的类,并利用延迟加载仅加载如果主机设备实际支持该功能,则该类在运行时。



这种方法的缺点是我必须使用SDK的SDK编译所有的代码我想要使​​用的最新功能这意味着如果某些新功能泄漏到我的版本中立代码中,编译器就无法再捕获它了。



我希望在Eclipse中编译我的能力针对较旧的Android SDK进行项目,以确保我的版本中立代码正常。如果可能,我想避免将我的构建系统移出Eclipse。我很好,这个旧的SDK构建有点尴尬的运行。



我认为这归结为做一些条件复制(或有条件的链接)里面蚀?例如,在我的项目中,针对SDK-1.6构建我想离开构建的MultiTouchHandler.java源代码。我不知道它是否可能在Eclipse中表达这样的构建类型。



黑客解决方案似乎只是手动更改项目的SDK版本,重建和查看错误,并忽略预期错误。



相关问题



这是一个非常实用的解决方案问题:
使用Eclipse进行版本控制和通用代码库
涵盖类似的理由,但将包括将所有特定于版本的类移动到单独的库中。 (我仍然会遇到Eclipse中的多种构建类型的问题,我想。)



这个问题:
使用eclipse构建多个项目配置意味着我应该移动到外部构建系统(如ant或maven),但这是更多的工作不仅仅是尝试使用旧的SDK的版本。

解决方案

2012年2月(v17)更新到ADT中的Lint工具应该有助于解决这个问题,而不需要多个构建。当一个应用程序定位到一个旧的最低SDK,但根据最新的SDK进行编译(按照推荐的做法),lint工具会注意到是否调用了较新的SDK。如果您确信通话是可以的(因为您已经将其隐藏在运行时SDK_INT检查或其他任何操作之后),则可以快速修复注释以防止发生警告。



例如,在我的代码中,我有一个调用View.setSystemUiVisibility,这是在API 11中引入的,但是我正在使用API​​ 8.运行Lint显示:


调用需要API级别11(当前最小为8):android.view.View#setSystemuiVisibility


QuickFix提出了两种修复方法:添加一个注释,该注释可以抑制警告,或添加一个声明一大段代码在API 11上的注释。



更多详细信息: http://tools.android.com/recent/lintapicheck


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.

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.

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.

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.

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.

Related Questions

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

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.

解决方案

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.

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:

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

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.

More details here: http://tools.android.com/recent/lintapicheck

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

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