操作系统版本,API级别和Java版本之间的关系 [英] Relationship between OS version, API Level, and Java version

查看:267
本文介绍了操作系统版本,API级别和Java版本之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这里有很多关于Android API等级和版本的问题,但这个问题有所不同所以请不要将其标记为重复。

I know there are a lot of questions on here about Android API Level and Version but this question is different so please don't mark it as a duplicate.

我想知道Java版本1.6,1.7,1.8 ......是如何与这两者相关的。我混淆的原因是我试图使用 Pattern.compile 方法和 Pattern.UNICODE_CHARACTER_CLASS 标志,如下所示。

I am wondering how Java version 1.6, 1.7, 1.8... relates to those two. The source of my confusion is me trying to use the Pattern.compile method with the Pattern.UNICODE_CHARACTER_CLASS flag as seen below.

Pattern pattern = Pattern.compile("\\b" + keywordToCheck + "\\b", Pattern.UNICODE_CHARACTER_CLASS);

来自 上的文档 Pattern.UNICODE_CHARACTER_CLASS 它说它说自:1.7,我认为它在Java 1.7及更高版本中可用。我试图在Android项目中使用该行代码,但每次我在我的设备上运行它时,我得到:

From the docs on Pattern.UNICODE_CHARACTER_CLASS it says that it says Since: 1.7, which I assume to mean it is available in Java version 1.7 and above. I am trying to use that line of code in an Android project but every time I run it on my device I get:

java.lang.IllegalArgumentException: Unsupported flags: 256

以下是我的build.gradle文件的相关部分

Below are the relevant parts of my build.gradle file

defaultConfig {
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

根据我的理解,这意味着我的应用程序将使用任何API级别19及以上,这意味着它可以在Android 4.4(KitKat)或更高版本上运行。我运行应用程序的设备有Android 6.0。 Java版本如何适应这个?我正在使用Android Studio 3.0,它说我正在使用:

From my understanding this means my app will use any API level 19 and above, which means it can run on Android 4.4 (KitKat) or higher. The device I'm running the app on has Android 6.0. How does the Java version fit into this? I am using Android Studio 3.0 which says I'm using:

Android Studio 3.0
Build #AI-171.4408382, built on October 20, 2017
JRE: 1.8.0_152-release-915-b08 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.6

有人可以向我解释为什么我会收到此错误,以及Android API Level,Version,和Java版本?谢谢

Can someone explain to me why I'm getting this error, and also the relationship between Android API Level, Version, and Java version? Thank you

推荐答案

在给定示例的情况下,直到 API 24 。在很多情况下,尽管先前添加了对给定语言级别(例如7)的支持并不意味着所有内容都会立即添加。有些事情是等待谷歌等待它的原因。

In the case of your given example, that flag wasn't added until API 24. In a lot of cases, even though support for a given language level (e.g. 7) was added earlier doesn't mean everything is added instantly. Some things are waited with for whatever reason Google has for waiting with it.

我不能告诉你为什么,因为我不知道。

I can't tell you why because I don't know.

正如Gabe所说,Java的版本不一定与Android兼容。

And as Gabe mentioned, the versions of Java isn't necessarily compatible with Android.

因为您的代码在API 19及更高版本上使用了标志,所以在19和23之间的版本上会出现崩溃,因为标志不是尚未添加。

So because of your code where you use the flag on API 19 and up, you'll get a crash on versions between and equal to 19 and 23 because the flag isn't added yet.

同样值得注意的是,版本兼容性并不限制Android版本的Java版本。现在,您可以在任何版本的Android上运行Java 8。这是兼容性。

And it's also worth noting that version compatibility doesn't limit versions of Java by versions of Android. Now you can for an instance run Java 8 on whatever version of Android you want. This is compatibility.

然而。如果您阅读 Android Java 8语言功能,它会说(强调我的) ):

However. If you read Android Java 8 Language Features, it says (emphasis mine):


Android Studio 3.0及更高版本支持所有Java 7语言功能和不同平台的 Java 8语言功能子集版本

我在这里使用Java 8作为示例,但这适用于大多数Android版本和java的。

I'm using Java 8 as the example here, but this applies to mostly every version of Android and java.

基本上:


  • 你的旗帜'在API 24之前没有添加使用.AFAIK,即使硬编码变量存在,也没有添加使用

  • Android不一定拥有每一个Java API,而这些因Android版本而异

  • Java版本不受API限制,但可访问的功能各不相同。这意味着你可以在API(随机数)12上运行Java 8。如果你愿意的话。

没有固定的关系(Android [x] = Java [x])两者之间。最终可以立即添加不同的字段/方法/类(在发布对给定版本的Java的支持时)或根本不添加。

There's no fixed relationship (Android [x] = Java[x]) between the two. Different fields/methods/classes may be added eventually, instantly (on release of support for a given version of java) or not at all.

Android中使用的常规Java和Java版本是两个非常不同的,因为Android是基于平台的,而Java是基于版本的。你无法比较它们之间的版本,它们都有单独的文档。

The regular Java and the version of Java used in Android are two very different ones, because Android is platform-based while Java is version-based. You can't compare versions between them, and they both have separate documentations.

值得注意的是,对于Android(Java)问题,你应该看一下Android文档可以在 API参考中找到,而不是使用不适用于Android因为API存在巨大差异。

It's worth noting that for Android (Java) questions you should look at the Android docs which can be found in the API reference instead of using the Oracle documentation which doesn't apply to Android because of the massive differences in the API.

这篇关于操作系统版本,API级别和Java版本之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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