1
\$\begingroup\$

I have set the jdk to Java 8 and I have modified all the build.gradle files in my project to have sourceCompatibility = 1.8 instead of 1.6. My problem is that while it does work on Desktop it doesn't when I run it on Android. Can someone tell me how to properly set up the project to use Java 8 so that it works on all platforms in IntelliJ?

\$\endgroup\$
  • \$\begingroup\$ Do you mean that it works for older version of java, but doesn't for java 8 ? \$\endgroup\$ – dimitris93 Jan 1 '16 at 21:38
  • \$\begingroup\$ Yeah, when java source = 1.6 it works on both android and desktop but when java source = 1.8 it works on desktop but on android it gives an error relating to DexDebug I remember. \$\endgroup\$ – BananyaDev Jan 1 '16 at 22:30
  • \$\begingroup\$ Just to mention, the variable inside the build.gradle was called sourceCompatibility not java source. Still the problem remains the same, if I change that variable to 1.8 it runs on desktop but not on android. \$\endgroup\$ – BananyaDev Jan 1 '16 at 22:50
2
\$\begingroup\$

I figured it out. Apparently Android does not support Java 8 yet, but you can use lambda expressions in Android. Here is a link to a page with a tutorial.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Android supports all Java 7 language features and a subset of Java 8 language features that vary by platform version. To enable those features add this to your build.gradle:

android {
  ...
  defaultConfig {
    ...
    jackOptions {
      enabled true
    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

To read more about Java 8 and Jack Toolchain in Android go to this link.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Android Studio in version > 3.0.0 natively supports some Java 8 features.

In Android Studio, go to File > Project structure > select android > Tab properties > Source compatibility > 1.8.

You will also need to set the target compatibility to 1.7 (yes, 1.7 because there is some conversion process involved to translate Java 8 features to be compatible with Java 7 native code)

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.