question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Backport to Java7/Android

See original GitHub issue

For an Android app, I had a need to parse a Cron expression and determine the previous/next execution date based on this expression. I came across this library but then realized it relies on JSR310 which was introduced in Java 8 and does not work with Android.

I forked the library and was able to make it work on Android in 2 steps:

Step 1: Make it work with Java 7

  1. Use threetenbp which is a backport of JSR310
  2. Search-and-replace all occurrences of java.time with org.threeten.bp
  3. Use retrolambda to be able to use java.util.function.Function and the lambdas in pre-Java 8

With this, I was able to successfully run all cron-util tests with a target of Java 7

Step 2: Make it work on Android

Here I started off with some tests for my own use case (parse a Cron expression and get the next/previous execution times), but I made them Android tests (i.e., run on an emulator). For this. I had to make some more changes in my app/tests

  1. Add ThreeTenABP which is an Android extension to threetenbp.
  2. Initialize ThreeTenABP in my test like this. If you use it in an app, you will still have to init it in your Application sub-class.
  3. Add a dependency on an implementation of SL4J. I used this one but any which works for you will do.

compile 'eu.lp0.slf4j:slf4j-android:1.7.22-0'

With these changes, I was able to run my app-specific tests successfully on Android.

Next steps

I left it at that because I am not sure how the maintainers would like to proceed with this. There are open questions like

  • Do you want to support Android in the first place?
  • If so, would you like to use JSR310 for Java8 targets and use the backport for older targets? Basically generate multiple versions of the library from the same code-base with multiple targets
  • Would you rather do some runtime shenanigans to detect if JSR310 is on the classpath and use that and fall back to the backport otherwise (don’t even know if this is possible!)
  • How would you like to approach the tests? For the Android target, It makes sense to run all the existing (408, at the time of this writing) tests on an emulator to make sure everything is compatible.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:27 (27 by maintainers)

github_iconTop GitHub Comments

1reaction
jmrozaneccommented, May 22, 2017

@curioustechizen version 6.0.0 was released with this changes!

1reaction
jmrozaneccommented, Apr 10, 2017

@curioustechizen sure. Just found out that we cannot setup a Java and Android language at the same time for Travis. I am thus deleting the Gradle project files at ‘master’ and will keep them at the ‘android’ branch, which will hold the Android Travis configuration as well. The deployed jar will still be a single one: the one from ‘master’, but the builds at ‘android’ should help us address issues early. Thank you for the help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Backported StreamSupport on Java 7/Android - Stack Overflow
streamsupport is a backport of the Java 8 java.util.function (functional interfaces) and java.util.stream (streams) API for users of Java 6 or 7 ......
Read more >
android-retrofuture - GitHub
android -retrofuture is a backport of the Java 8 CompletableFuture API upgraded to the current Java 9 (JEP 266) enhancements for Android developers...
Read more >
Show HN: Java 7 Features Backported to Android
Lambdas are in JDK 8 while Android supports JDK 6. This adds support for some of the features of JDK 7. That said,...
Read more >
Use Java 8 language features and APIs - Android Developers
Use Java 8 language features and APIs ... Android Gradle plugin 3.0.0 and later support all Java 7 language features and a subset...
Read more >
Choosing an Optional Backport - Medium
Being an Android developer, I am basically stuck with Java 7 . To make development better, I use RetroLambda and I love it....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found