4

The official Java 8 announcement for Android N Preview says the following:

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. (…) Some Java 8 language features — like default and static methods, streams, and functional interfaces — are also now available on N and above.

I'm using the following gradle configuration with minSdkVersion 15 to try some Java 8 in a small project:

android {
    compileSdkVersion 'android-N'
    buildToolsVersion '24.0.0 rc1'

    defaultConfig {
        applicationId "org.sergiiz.thermometer"
        minSdkVersion 15
        targetSdkVersion 'N'
        versionCode 1
        versionName "1.0"
        jackOptions{
            enabled true
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
   //...
}

But the Deployment Target selector shows minSdk(API23, N preview). Is it expected behaviour?

enter image description here

Is there a list of Java 8 features/packages available as far back as Gingerbread and do you know which gradle settings or support libs are needed to use Java 8 features on API<23?

Sergii
  • 1,521
  • 3
  • 24
  • 37
  • I can't help you with the Gradle settings (haven't tried myself yet). But the list of supported Java 8 features in pre-Android N is easy: It's lambda expressions / method references only - nothing else to my knowledge. – Stefan Zobel Mar 29 '16 at 15:33
  • 1
    Possible duplicate of this one: http://stackoverflow.com/questions/35929484/android-n-cannot-run-on-lower-api-though-minsdk-set-to-14 – Stefan Zobel Mar 29 '16 at 17:25

1 Answers1

2

But the Deployment Target selector shows minSdk(API23, N preview). Is it expected behaviour?

Yes. The N Developer Preview is set up to only run on N devices. Your targetSdkVersion 'N' line is implicitly changing your minSdkVersion to also be N.

do you know which gradle settings or support libs are needed to use Java 8 features on API<23?

I recommend that you not worry about the Java 8 features on older devices until Android N exits "developer preview" mode or the Android tools team provides specific non-N instructions.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491