Does ADT support Java 8 API? - java

Do Android Developers Tools support JAVA 8 API up to this date? I'm trying to build an Android app using JAVA 8 and I was wondering about this thing.

Java 8 APIs started becoming available in Android API 26 (which is Android 8, or Nougat). A mechanism called API desugaring is available to use certain Java 8 APIs on earlier Android versions, regardless of the Android API level.
However, there is no 1:1 connection between Android and Java API versions. In the past, it has taken Google some 2–3 years following the release of a new Java version to gradually start implementing its APIs. So, the question “is a certain Java API available on a certain Android version” can only be answered on a per-class/member base. You will have to look up every class, method, constant etc. on the Android API reference and see if it it supported, and what the minimum API version on Android is – or see if API desugaring provides it, which is not tied to a particular Android API level.

Related

Application API LEVEL 26 and Android 7?

I am new to android development . I have a simple question. If the method was introduced in API LEVEL 26 , can it be run on a device that has Android 7 OS?
Here's a list of Android versions and API levels.
As you can see, Android 7.0 has API level 24. So the method will not be available as it was introduced later.
If the method in question is a standard Java method, in particular a method from java.time, java.nio.file orjava.lang.invoke, then it might be available through API desugaring independent from the API level.

Will my app run on android 4.0 if I use JDK 8

My android studio project uses the embedded JDK which is version 8 by default im wondering will my app still run on android 4.0 and 5.0 devices ?
The app will definitely run with JDK 8 run it.
Android Studio 3.0 and later supports all Java 7 language features and a subset of Java 8 language features that vary by platform version.
Android Studio provides built-in support for using certain Java 8 language features and third-party libraries that use them.
Note:
When developing apps for Android, using Java 8 language features is
optional. You can keep your project's source and target compatibility
values set to Java 7, but you still need to compile using JDK 8.
And about your minSDK comment "whats your preferred minSDK? if you start with API 19 you have a rate of 95%"->
minSdk is required to set the minimum api level run environment(android OS version) to the application. If you choose minSdk the minimum possible you can target max number of devices.
If you want to use JDK8 to compile your Android app there is no problem with it, you can easily set compatibility to Java 6/7 and there won't be any issues.
If you want to use Java 8 language features it all depends on the mindSdkVersion that you have set up. You can freely use:
- lambda expressions
- method references
- default and static methods in interfaces
- repeating annotations
Java 8 API is available from API level 24 unfortunately in your case you won't be able to use any Stream API and such.
For more information please check:
https://developer.android.com/studio/write/java8-support

How to use Java-specific functions in previous api levels?

Some java specific libraries asks for android min API 26. For example Base64.getUrlEncoder() asks for android min API 26. How can I use these java properties in previous api levels? I tried to increase compile java options to latest java version but still I'm not able to use in previous api levels. So is there any way to do this?
No you can't use those APIs below the stated minSDK.
Some APIs are cloned in the Support Library. Base64.getUrlEncoder() is not.
However you could use the Android Base64 version which is available since API 8.

Which Java distribution 'level' does Gluon *Mobile* JavaFX expose, for IOS and Android - i.e. Full JavaSE (desktop) or Android?

Apologies, I'm new to both JavaFX and Gluon Mobile.
As JavaFX is/was a desktop API, I'm trying to understand exactly which level of API's Gluon Mobile exposes (compiles against) for Android and IOS? This doesn't seem to be made explicitly clear.
Once this is understood, I can better understand if I'm able to use some 3rd party API's I'm interested in, which utilise JavaSE desktop API's (specifically Javax sound), on mobile (via Gluon).
You may want to have a look at the Gluon's knowledge base about Java 8 and JavaFX 8 features.
At the moment, Android is using the Harmony implementation of the Java SE API’s, which is somewhere between Java 6 and Java 7. This means that new Java 8 features like lambdas and streams are not supported. For both cases there are workarounds like the retrolambda and the streamsupport projects.
As for JavaFX 8 features, Media API or Printing API are not included yet.
But if you need it, you can include in your project a native solution. Have a look at the GoNative sample for a use case. Media could be added as well via NDK.
OK, I read Oracle's Writing JavaFX Applications for Mobile Devices and:
the internal implementation of JavaFX 8 on Android and iOS does not use Java SE 8–specific APIs
The quote above relates to the usage of OpenJFX on mobile, which Gluon Mobile itself is based upon.
So there we have it, no JavaSE Desktop in Gluon Mobile/Mobile JavaFX apps.

How does Android's Java version relate to a Java SE version?

I am constantly wondering how the Java version used for Android development relates to a Java SE version. For example, I was reading today about "Type Inference and Generic Methods" which is a feature added in Java SE 7. I wonder to myself, "Can I use this in Android code?"
Of course I could type the code into an Android project and see if it compiles, but I'd be happier to have some kind of mapping in my head.
I've tried Googling for this info, checking the Android docs, etc, but can't find an answer.
Edit: I'm more interested in language features, e.g. how does the Android Java syntax version relate to Java SE syntax.
Android's version doesn't directly relate to Java SE, although it uses a subset of Apache Harmony's SE 6 libraries and tools. It will be up to the Android team to decide if & when to support/require the SE 7 version of Harmony.
Edit It looks like as of KitKat Android supports Java SE 7 language features. See the comments below.
There is no direct mapping:
Some parts of the API (such as JAXB, which has been around since at least Java 6) have never been available on Android.
When features of a new Java version are introduced, this can happen gradually over multiple versions.
Some newer Java features are made available for older, already-released versions as backports.
In the past it has taken Google some 2–3 years to start adopting a new Java version. Java 7 features started appearing around API 19 (KitKat). Java 8 features started at API 26 (Nougat), but a mechanism called desugaring is available to make certain Java 8 features available on earlier Android versions, regardless of their API level.
So, generally speaking, if you want to know whether a particular Java API feature is available on Android, look it up on the Android developer reference and check the minimum API version.

Categories