我是 Android 开发的新手。我可以在 Android 中使用使用 JDK 7 开发的现有 Java 代码吗?
函数使用 xerces dom 和 xslt 和 xpathapi。目前,当我安装 Android Eclipse ADT 环境时,这些功能没有编译。我也想知道Android设备本身支持JRE 6还是7?
最佳答案
最初的 Android 开发工具只支持 jdk 6 功能。但这种情况发生了变化,首先是 2013 年 10 月的 Android Studio 0.3.2,参见:http://tools.android.com/recent/androidstudio032released
Support for language features like the diamond operator, multi-catch, try-with-resources, strings in switches, etc. When creating a new project, you can specify a source language level: Note that you can use all these language features not just with Android KitKat, but with older versions of Android too! There is one exception to that: try-with-resources, which will require minSdkVersion 19. Therefore, Studio will flag any uses in your code of try-with-resources if your minSdkVersion is less than 19:
然后在 2014 年 3 月通过 ADT 插件 22.6,请参阅:http://developer.android.com/tools/sdk/eclipse-adt.html
Added support for Java 7 language features like multi-catch, try-with-resources, and the diamond operator. These features require version 19 or higher of the Build Tools. Try-with-resources requires minSdkVersion 19; the rest of the new language features require minSdkVersion 8 or higher. To use the new language features after installing ADT 22.6.0, ensure that you run Eclipse on JDK 7 and change your application project settings to use JDK 7.
Android 并不打算与任何 Java SE API 版本 100% 兼容,既不是 6 也不是 8 也不是任何版本。这就是甲骨文对谷歌提起诉讼的原因,指控谷歌将Java fragment 。有些 API 无法在 Android 上作为 Swing 实现;想象一下在 android 上有一个带有关闭按钮的窗口!其他延迟但已实现:例如:Charset 类在 Java SE 1.4 中但在 android API 9 中实现,在 Java 7 中的 AutoClosable 在 Android API 级别 19 中实现以允许实现 try-with-resources 语言功能。一些 API 是存在的,但用于与控制台不同的目的。
关于android - Android 是否支持 JDK 6 或 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20480090/