From cdf04a56cf507ec3f1d609e383857929c03b555b Mon Sep 17 00:00:00 2001 From: Adarsh Fernando Date: Tue, 8 Mar 2016 18:27:27 -0800 Subject: [PATCH] Docs: Added Java 8 and Jack coverage for N Preview Change-Id: I6eaf7f5115c1d3117eefaf7cb0cbeddaa46ad437 --- docs/html/preview/j8-jack.jd | 227 +++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 docs/html/preview/j8-jack.jd diff --git a/docs/html/preview/j8-jack.jd b/docs/html/preview/j8-jack.jd new file mode 100644 index 0000000000000..e4d7d946b2a56 --- /dev/null +++ b/docs/html/preview/j8-jack.jd @@ -0,0 +1,227 @@ +page.title=Using Java 8 Language Features +page.keywords="android N", "Java 8", "Jack" +@jd:body + +
+ +
+ +

+ The N Developer Preview introduces newly supported Java 8 language features + that you can use when developing apps that target the Preview. To start using + these features, you need to download and set up Android Studio 2.1 (preview) + and the N Preview SDK, which include the required Jack toolchain and updated + Android Plugin for Gradle. +

+ +

+ To learn how to set up Android Studio for the Preview, read the guide. If you instead want to + simply test your app's forward-compatibility, follow the guide to run your app on + the N Preview. +

+ +

+ This document will discuss the new language features supported in the + Preview, how to properly set up your project to use them, and any known + issues you may encounter. +

+ +

+ Note: Using the new Java 8 language features is not a + requirement for developing apps that target the N Developer Preview. After + following the set up instructions in the Preview guide, you may use + the Java 7 language features already supported by Android 6.0 (API level 23) + and below. +

+ +

+ Supported Java 8 Language Features and APIs +

+ +

+ Android does not currently support all Java 8 language features. However, the + following features are now available when developing apps targeting the N + Developer Preview: +

+ + + + +

+ Additionally, the following Java 8 language feature APIs are now available + with the Preview: +

+ + + +

+ Note: The N Developer Preview bases its implementation of + lambda expressions on anonymous classes. This approach allows them to be + backwards compatible and executable on earlier versions of Android. To test + lambda expressions on earlier versions, remember to go to your {@code + build.gradle} file, and set {@code compileSdkVersion} and {@code + targetSdkVersion} to 23 or lower. +

+ +

+ Enabling Java 8 Features and the Jack Toolchain +

+ +

+ In order to use the new Java 8 language features, you need to also use the + new Jack toolchain. This new + Android toolchain compiles Java language source into Android-readable dex + bytecode, has its own {@code .jack} library format, and provides most tool chain + features as part of a single tool: repackaging, shrinking, obfuscation and + multidex. +

+ +

Here we compare the two toolchains used to build Android DEX files:

+ + +

+ Configuring Gradle +

+ +

+ To enable the Java 8 language features and Jack for your project, enter the + following in your module-specific {@code build.gradle} file: +

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

+ Known Issues +

+ +

+ Instant Run, introduced in Android Studio 2.0 (Beta), does not currently work + with Jack and will be disabled while using the new toolchain. +

+ +

+ Since Jack does not generate intermediate class files when compiling an app, + tools that depend on these files do not currently work with Jack. Some examples of + these tools are: +

+ + + +If you find other problems while using Jack, please report bugs. \ No newline at end of file