0

Compiling with ecj on Termux produces the following error message:

Lambda expressions are allowed only at source level 1.8 or above.

No options were specified when running the tool.

Compiling with switch - 1.8 produces the following output:

ecj -1.8 Composite2

duplicate compliance setting specification: -1.8

Composite2 is the directory where my source code resides.

I tried the following next:

ecj -source 1.8 -target 1.8 Composite2

Compliance level '1.7' is incompatible with source level '1.8'. A compliance level '1.8' or better is required.

The source is available here

Are there any settings or switches I'm missing? I'm unfamiliar with using ecj as a compiler.

Can you help?

There appears to be solutions like Retro Lambda and backporting to make Java 8 source work on 7 or earlier. I have yet to try it though. There's only so much one person can check out. ( See comments below for clarifications).


A workaround might be to install Arch Linux on Termux.. The command prompt can be a bit buggy, though.

You can then install Open JDK 8 and eclipseecj using the package manager pacman.

That worked; ecj now compiles 1.8 code.

I wished to avoid installing the full JDK since it introduces redundancies and consumes additional space.

Linus Fernandes
  • 498
  • 5
  • 30
  • Please check: what exactly is `ecj` on your system? Seems to be a script that has some options hard coded? Does that script have its own help / manual? – Stephan Herrmann May 04 '19 at 19:20
  • #!/data/data/com.termux/files/usr/bin/sh # -proc:none to disable annotation processing. # -7 for java 1.7 compatibility. dalvikvm -Xmx256m \ -cp /data/data/com.termux/files/usr/share/dex/ecj.jar \ org.eclipse.jdt.internal.compiler.batch.Main \ -proc:none \ -7 \ -cp /data/data/com.termux/files/usr/share/java/android.jar \ "$@" – Linus Fernandes May 04 '19 at 20:51
  • The above is the content of the script ecj. You may be onto something. Let me check it out and see if it works for 8 and 9. Thank you in advance. – Linus Fernandes May 04 '19 at 20:53
  • I uncommented one of the lambda expressions in my Main.java file. I received the following compile error: ERROR in /data/data/com.termux/files/home/LearnJava/Composite2/design/composite/Main.java (at line 1) package design.composite; ^ The type java.lang.invoke.LambdaMetafactory cannot be resolved. It is indirectly referenced from required .class files ---------- 1 problem (1 error) From what I've googled, this appears to be a problem with pointing to the wrong JRE. I changed 7 to 8 in the ecj script. The source is at https://github.com/Fernal73/LearnJava/tree/master/Composite2 – Linus Fernandes May 04 '19 at 21:09
  • The /usr/share/java directory has another jar as well. android-21.jar. That doesn't appear to be the one I'm looking for. – Linus Fernandes May 04 '19 at 21:27
  • Do I require newer versions of either the android.jar or ecj.jar files or both? Where can I get them from? – Linus Fernandes May 04 '19 at 21:51
  • I found this article by Jake Wharton that talks about desugaring. I haven't developed for Android before. So I'm unfamiliar with Android tooling. But it does seem that I'll need Android 26 API or higher. https://jakewharton.com/androids-java-8-support/. For lambda, that is. – Linus Fernandes May 05 '19 at 01:57
  • I also found this: https://stackoverflow.com/q/24943726/3924108 – Linus Fernandes May 05 '19 at 02:09
  • https://developer.android.com/studio/write/java8-support I also found this but this doesn't specify how to change any specific settings for dalvikvm. – Linus Fernandes May 05 '19 at 04:15

2 Answers2

1

Termux on Android 7 does not support any java versions beyond 7. ARCH Linux on Termux supports up to Java 13. The best option is to install OpenJDK on Arch Linux for Termux and use javac as against ecj. There are other issues with ecj on Arch Linux as well such as support only till Java 8.

Linus Fernandes
  • 498
  • 5
  • 30
0

This appears to be a bug in ecj that was reported https://bugs.eclipse.org/bugs/show_bug.cgi?id=535969 here, and patched https://bugs.eclipse.org/bugs/show_bug.cgi?id=477894 here.

Verified with Eclipse 4.9 m2 Build id: I20180731-0800