Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Android apps use java 8 compiled jars?

Tags:

java

android

Let's say I create a java library independent of the Android framework. Classes/methods in this java library have been written with Java 8 streams and lambdas. I then compile my java library into a jar and add it as a dependency in my Android project.

Can my android app use that jar even though Android itself only supports Java 7?

Thanks for any info.

like image 737
Kurt Mueller Avatar asked Jan 06 '15 01:01

Kurt Mueller


People also ask

Can I use Java 8 for Android?

Android does not support Java 8. It only supports up to Java 7 (if you have kitkat) and still it doesn't have invokedynamic, only the new syntax sugar. If you want to use lambdas, one of the major features of Java 8 in Android, you can use gradle-retrolamba.

What version of Java does Android use?

Class libraryJava 8 source code that works in latest version of Android, can be made to work in older versions of Android.

What is Desugaring in Android?

The desugaring process rewrites your app's code to instead use this library at runtime. To enable support for these language APIs on any version of the Android platform, update the Android plugin to 4.0.0 (or higher) and include the following in your app module's build.gradle file: android {

Can program developed with Java 7 be run on Java 8?

In general, no. The backwards compatibility means that you can run Java 7 program on Java 8 runtime, not the other way around. There are several reasons for that: Bytecode is versioned and JVM checks if it supports the version it finds in .


Video Answer


1 Answers

Do you explicitly need Java 8 compiled JARs? Otherwise you can use a retro-compiler.

I plan to use retrolambda to integrate Java 8 code into my Android project.

like image 120
Jan Groth Avatar answered Oct 13 '22 06:10

Jan Groth