Android Studio - Kotlin with JVM Target 1.8 - java

The newer version(s) of Android Studio default Kotlin projects to target JVM 1.8. Considering that Java 8 is about six year old now, that looks like a sensible default, but is there any downside? Any compatibility issues, like not being able to target older API, etc? There is a doc describing certain issues with 1.8 and AS 3.0 - https://developer.android.com/studio/write/java8-support
Does it mean that with the latest stable build of AS (3.6.3 at this time) those issues are gone?

Related

Using JJWT on JDK 1.6

On the main page I noticed that JJWT is supposed to run on all JDK, which - since our project for all sorts of reasons is still stuck on v1.6 - sounded great.
With the last version maven retrieves however, the class version is not compatible.
And afterwards in the build wiki I noticed it specifies version 7.
Anyone have a clue what does run on v1.6.
Can I use an older version, or should I compile it myself maybe.
On the main page I noticed that JJWT is supposed to run on all JDK ...
That is definitely incorrect / inaccurate. The initial commits for the JJWT project were for JDK 1.6. And I can see that the code uses generics, so compiling / running for earlier than JDK 1.5 will be impossible.
The POM.xml file for the latest version of the project sets the source and target version for the project to JDK 1.7. So certainly the artifacts that a standard build will generate now will NOT run on a Java 6 platform. The class file version will be too recent for a Java 6 JVM to understand.
Now you could try changing the JDK level to 1.6 in the POM file in the HEAD version. However, the JDK version for JJWT was bumped past 1.6 four years ago, so there are liable to be build issues if you wind back. (The developers could have introduced Java 7+ dependencies; e.g. using try with resources syntax or Java 7+ APIs.)
A better idea would be to use an old version of JJWT. You should be able to figure out what version you need to use (or build) for JDK 1.6 compatibility by looking at the project's git history on Github. Look at the relevant changes to the POM file and when they happened. I think it is version 0.9.0 or thereabouts.
Of course a better solution would be "unstick" your project. JDK 1.6 is 8 years past its end of life, and 3 years past the end of Oracle's JDK 1.6 (paid) extended support.

Cannot resolve some classes of jdk 8 in android studio

I am using jdk1.8.0_31. But i cannot implement class in my project YearMonth which introduced in jdk 1.8. My concept on jdk is not clear. Is there any relationship between jdk version vs api version (Compatibility issues) ? Is the all features are inherited in android after release of latest jdk ?
If you go to File/project structure in android studio and for source compatibility select 1.8 you can't because android studio doesn't. This lawsuit explains why google is not so eager to support java for now. As for time/year/month/dates etc. Java 8 has instant for recording times and dates ...
Check your android API and see what java versions are supported. Most of the time when an api is designed a lot of efforts put in place to support lower JDK(specially > JDK 1.5) versions but the people don't have control on latest Java versions.
Minimum SDK level defines what you can use or not. Java 8 is currently not supported by Android. Please refer the below post for more details
Which JDK version (Language Level) is required for Android Studio?
API level with JRE versions

Eclipse/Java - JDK Compliance

This may seem a daft question so I will be as brief as possible.
Where I work, we deal with lots of Java apps that are compiled on old versions of Java, in fact we recently upgraded one of them to Java 1.6
We've been given new laptops recently with no admin rights and Java 7 installed by default.
I am presently unable to get hold of and install a copy of JDK 1.5 (which I need)
In Eclipse, if I set my JDK Compliance level to 1.5 but the Installed JRE is 1.7
Which of these 2 statements is true... ?
1. I am building my code at Java 1.5 ?
2. I am building my code at Java 7 ?
I've seen and spoken to various people on this subject and I am still non-the-wiser.
It means the byte code that is generated from your source code will be compliant to the 1.5 JRE.
The syntax highlighter will not allow you to do things that were new to 1.6, 1.7 such as switching on strings.
Developing with a JDK higher than the target platform is in principle possible, using the "compliance settings" and/or target version switches with javac.
Its however not practically feasible for doing real development, as nothing will prevent/warn you from using the API's present in your installed JDK but not in the target platform.
If, for example you develop for java 1.4 using an installed 1.5, while the compiler will not let you use autoboxing (which was introduced in 1.5), but it will happily let you use (for example) Integer.valueOf(int). Which is not present in 1.4.

Does it matter what version of JDK I use in Android Studio?

I know I can choose the SDK location in Android Studio's Project Structure.
I have two questions:
Why do we need JDK when we are already using Android SDK? After all, we are not developing for JVM.
Is there any difference between using JDK 1.6, 1.7 and 1.8?
Why do we need JDK when we are already using Android SDK? After all, we are not developing for JVM.
The Android build process depends on a number of tools from the JDK. Check out the build system overview documentation.
The first big piece we need from JDK is javac- all your source code written in Java needs to be compiled before it can be converted to the DEX foramt.
Once your code has been compiled, dexed, and packaged into an APK, we need jarsigner to sign the APK.
Is there any difference between using JDK 1.6, 1.7 and 1.8?
That depends on what features you are using from each. Older projects that don't use Java 7 features can use Java 6 without issue. I personally recommend Java 7 for most modern projects. If you can use it, why not?
There are some efforts out there to bring Java 8 features to Android, most notably gradle-retrolambda. Some of these require JDK 8 to compile properly.
Android always supported Java 6.
Android now support Java 7 so that is the recommended one (since KitKat).
Android does not support Java 8 as of yet.
You can specify Java 7 like so in your build.gradle file:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
The only difference being the Java version (Java 7 adds features of course) and the fact that Android does not support Java 8 period.
EDIT
Actually this was answered here: Which JDK version (Language Level) is required for Android Studio?

J2ME with java 1.6

I'm using CLDC 1.1 + MIDP 2.0 .
The "Compiler compliance level" is set to 1.4 .
When I set "Compiler compliance level" to 1.6, I get the following error: "ALERT: java/lang/ClassFormatError: Bad version information.".
How can I use java 1.6 with J2ME?
This answer maybe outdated now, please refer below for latest answers.
Date: April 2011
How can I use java 1.6 with J2ME?
You can't
Core Reason: J2ME is meant for mobile device where the memory & cpu are the biggest constraint.
Java ME is a subset of Java, and most of the ME specific code will reside mostly on the client, so you don't need any special versions of Java to compile the program.
The problem here is that you are using a version of Java compiler that didn't exist when the phone was invented. The version of the Java compiler is written to the .class compilation output.
Ideally you would compile the project with an older version of Java, but it is very hard to install an old version. So we can act as a compiler ourselves, and manually set the version in the .class output files to the version we desire, and we should make sure that we don't use features from after that version. In this case we will target version 1.2.
You can use the -source and -target options of the compiler to prohibit as many features as possible but many javac compilers have a limit to the older versions they can target, my Java 9 (1.9) can go as low as 1.6. You will need to manually ensure that you are not using features introduced between 1.2 and 1.6
The first 4 bytes in a .class file are the infamous "CAFEBABE" magic string.
bytes 5 and 6 are usually 0
bytes 7 and 8 are the java minor and major versions.
Change Byte 8 to 0x2E. According to https://en.wikipedia.org/wiki/Java_class_file this corresponds to version 1.2 or Java2.
We are using Java2 because, as you can see in its initials J2ME, Micro Edition was released in Java 2. So for backwards compatibility reasons, you can be fairly confident that the phone will run such applications. If you need features introduced after this Java version, just keep increasing the version number until it fails again to find out the exact version of Java supported by your phone.
you can not use it because it is for se and ee version not compatible with mobile
latest sdk for j2me 3.0 is available

Categories