-2

I am using eclipse to develop android.My eclipse version is MARS 4.5.2.I tried to use JAVA8 to compile android N,but when I changed the jdk to 1.8. An error occurs

Android requires compiler compliance level 5.0 or 6.0. Found '1.8' instead.

Any helps will be appreciate.

I must use JDK1.8 to build the project. So i shouldnot change the jdk to 1.6 or 1.7. Because android N need jdk 1.8 to compile. I have compiled the android N projcet succesfully with jdk 1.8 on Windows. But I cannot compile it on MAC

greg-449
  • 109,219
  • 232
  • 102
  • 145
chefish
  • 517
  • 2
  • 7
  • 20

1 Answers1

1

Basically, the problem is that you cannot compile Java 8 source code for Android.

  • If you have to use Java 8 code, you cannot run it on Android.

  • If you have to run on Android, you cannot use Java 8 code.

It is not a problem with your IDE. Eclipse Mars >>does<< support Java 8. It is just that Mars with the Android tool-chain does not. Because the Android tool-chain itself does not support Java 8.

The real issue is that the Android >>platform<< doesn't support dex-ing of Java 8 bytecodes, and doesn't provide Java 8 compatible runtime libraries.


On reflection, maybe I have misinterpreted your question. Perhaps the problem is that you can't make Eclipse compile for Java 5 / Java 6 ... because you haven't provided it with a Java 5 or Java 6 JRE / JDK to compile against.


I found (here) that the Android N SDK toolchain is supported for Android Studio, with no sign of any support in Eclipse. In fact, the Getting Started page for the Android N preview says that you need Android Studio 2.1.

My recommendation would therefore be to use Android Studio 2.x for your Android app development, both classic Android and Android N.

Don't try to use Eclipse for Android N.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • But I can use it successfully on Windows. It only have problems on mac – chefish Apr 14 '16 at 07:47
  • I did not used JAVA 8 code. I just want to compile Android N – chefish Apr 14 '16 at 07:48
  • 1
    1) I seriously doubt it. You are most likely compiling with an earlier compliance level. 2) If you don't use Java 8 code, don't compile with a Java 8 compliance level. Compile with a compliance level that is supported! – Stephen C Apr 14 '16 at 07:49
  • @chefish What does windows/mac have to do with the Android OS?.. I've googled a bit, and from what I can find Android isn't supported for Java 8, although it will be in the very near future. [At the bottom of this SO-post (ordered by post date) there are some answers mentioning it will be supported (soon).](http://stackoverflow.com/questions/23318109/is-it-possible-to-use-java-8-for-android-development?answertab=oldest) So _Stephen_ is right that it isn't supported at the moment. – Kevin Cruijssen Apr 14 '16 at 07:53
  • @KevinCruijssen you can see this http://developer.android.com/intl/zh-cn/preview/j8-jack.html – chefish Apr 14 '16 at 07:55
  • @StephenC I am sure I used jdk 1.8 to compile android N project on Windows. And android N project must need jdk 1.8, you can see this http://developer.android.com/intl/zh-cn/preview/setup-sdk.html – chefish Apr 14 '16 at 07:59
  • @StephenC I am sorry I did not explained it clearly . I ONLY want to use jdk 1.8 to buid my android N projcet. – chefish Apr 14 '16 at 08:19