Is it possible to use Java 8 for Android development?

后端 未结 26 1963
礼貌的吻别
礼貌的吻别 2020-11-21 22:50

Searching the web, it is not clear if Java 8 is supported for Android development or not.

Before I download/setup Java 8, can some one point me at any \"official\" d

相关标签:
26条回答
  • 2020-11-21 23:11

    Easiest way to add Java 8 support

     compileOptions {
        targetCompatibility = '1.8'
        sourceCompatibility = '1.8'
     }
    

    Just add it in your build.gradle file.

    0 讨论(0)
  • 2020-11-21 23:13

    java 8

    Android supports all Java 7 language features and a subset of Java 8 language features that vary by platform version.

    To check which features of java 8 are supported

    Use Java 8 language features

    We've decided to add support for Java 8 language features directly into the current javac and dx set of tools, and deprecate the Jack toolchain. With this new direction, existing tools and plugins dependent on the Java class file format should continue to work. Moving forward, Java 8 language features will be natively supported by the Android build system. We're aiming to launch this as part of Android Studio in the coming weeks, and we wanted to share this decision early with you.

    Future of Java 8 Language Feature Support on Android

    Eclipse Users:

    For old developers who prefer Eclipse, google stops support Eclipse Android Developer tools

    if you installed Java 8 JDK, then give it a try, if any problems appears try to set the compiler as 1.6 in Eclipse from window menu → PreferencesJavaCompiler. Java 7 will works too:

    Eclipse Preferences -> Java -> Compiler

    Java 7 or higher is required if you are targeting Android 5.0 and higher.

    install multiple JDK and try.

    0 讨论(0)
  • 2020-11-21 23:13

    Android uses a Java that branches off of Java 6.

    As of Android SDK version 19, you can use Java 7 features by doing this. No full support for Java 8 (yet).

    0 讨论(0)
  • 2020-11-21 23:13

    I asked this question over 3 years ago and obviously the answers have changed over the years. As many above have already answered, as of sometime back, the answer became Yes. I have never updated the accepted answer because it was the correct answer at the time. (I am not sure what the Stack Overflow policy is on that)

    I just wanted to add another answer for those who still search for this topic. As of 5/17/2017 Google also announced that Kotlin is also an official language for Android development.

    I have not found an official press release, but I did watch some of the Google I/O videos where it was announced. Here is a link to a blog post by the Kotlin team on the announcement.

    0 讨论(0)
  • 2020-11-21 23:14

    We Can Use Java 8 using:

    1. In build.gradle (Project: myProject) add following

      classpath 'me.tatarka:gradle-retrolambda:x.x.x' //x.x.x is recent version
      
    2. In build.gradle (Module: myModule) add following

      apply plugin: 'me.tatarka.retrolambda'
      
      compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_8
          targetCompatibility JavaVersion.VERSION_1_8
      }
      
    0 讨论(0)
  • 2020-11-21 23:15

    Android OFFICIALLY supports Java 8 as of Android N.

    Feature announcements are here, the Java 8 language announcement is:

    Improved Java 8 language support - We’re excited to bring Java 8 language features to Android. With Android's Jack compiler, you can now use many popular Java 8 language features, including lambdas and more, on Android versions as far back as Gingerbread. The new features help reduce boilerplate code. For example, lambdas can replace anonymous inner classes when providing event listeners. Some Java 8 language features --like default and static methods, streams, and functional interfaces -- are also now available on N and above. With Jack, we’re looking forward to tracking the Java language more closely while maintaining backward compatibility.

    0 讨论(0)
提交回复
热议问题