Question
Which Android versions run which Java versions?
I've just tried to run my app compiled using Java 8 on an Android 4.0 device. While I'm used to taking great care to look at the Android API levels in the Android documentation to make sure I'm only using APIs that are available on Android 4.0, I'm not so used to making sure I'm not using any features in Java itself that aren't available on Android 4.0.
Consider the following code, it tries to import the initializeScrollbars()
API from View
class because, for whatever reason, it has been removed from the official SDK:
try {
final Method initializeScrollbars = android.view.View.class.getDeclaredMethod("initializeScrollbars", TypedArray.class);
initializeScrollbars.invoke(this, a);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
While this code works fine on my Android 8.0 test system, it doesn't work on Android 4.0. The error is:
Could not find method java.lang.ReflectiveOperationException.printStackTrace
After some research I found out that ReflectiveOperationException
is not available before Java 7 and so, apparently, Android 4.0 does not support Java 7.
This makes me wonder: Is there an overview which clearly shows which Android versions come with which Java version? e.g. how can I find out the first Android version that supports Java 7? And how can I find out the first Android version that supports Java 8?
This really must be easy to find but I'm just failing to see it. Googling always leads to results in which people are asking about the Java versions supported by Android Studio, not by Android itself.
So, can anybody please shed some light onto this? I know it must be somewhere really obvious, but I don't seem to find it...