9

Android SDK requirements state that either JDK 5 or JDK 6 is required.

However, I have a Java class library written in Java 7 and I would like to use it for my Android project.

Instead of manually converting Java 7 to Java 6 by hand, I was wondering if anyone know of a converter that could do this job for me?

Or do we have to code one up from scratch?

Pacerier
  • 86,231
  • 106
  • 366
  • 634
  • 2
    99.9% of the code should need no conversion, unless the developers were enamored of some Java 7 feature. And the other 0.1% likely requires thought. – Hot Licks Jan 15 '12 at 13:34
  • @HotLicks I'm talking about things that could be automated (so we don't have to manually go through the classes in the entire library copy and pasting code). For example, the inferred diamond parameters and switch on String. – Pacerier Jan 15 '12 at 13:44
  • NetBeans can automatically convert code from older versions to code with Java 7 features. But I don't know if it can do it the other way around... – Jesper Jan 15 '12 at 14:10
  • For Java 5 to 1.3 case, it was called "retrotranslator," or "retroweaver," check out http://retrotranslator.sourceforge.net/, http://www.glazedlists.com/Home/declawer, http://www.jboss.org/jbossretro, and http://retroweaver.sourceforge.net/index.html; I cannot see a Java 7 version of anything similar. – alf Jan 15 '12 at 14:21
  • 2
    Is there an option with Java 7 to compile to Java 6 bytecode? Java 1.5 had that, to generate Java 1.4.2 bytecode. At the end of the day, you may not necessarily need Java 6 *source* as much as you need a Java 6 *JAR*. – CommonsWare Jan 15 '12 at 14:22
  • @CommonsWare It's not possible to compile to Java 6 bytecode if I use Java-7-only language features within the source code. – Pacerier Jan 15 '12 at 15:09

1 Answers1

1

Do you have the source for the JAR? If so, you can use the javac -target parameter set to either 5 or 6 to generate either Java 5 or 6 class files. See this page.

Kaleb Brasee
  • 51,193
  • 8
  • 108
  • 113