Error:Data Binding does not support Jack builds yet - android

I am implementing DataBinding, it is working perfect, but it is not allowing me to use jackOptions. It throws error Data Binding does not support Jack builds yet while build.
Here is my build.gradle
android {
defaultConfig {
...
dataBinding {
enabled true
}
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

From yigit's comment it's clear that this functionality is still under development as he and George are project member of DataBinding.
we are working on it... yigit
I have also found that issue is already reported Issue 210615: Databinding with Jack compiler
UPDATE
2.3 will allow you to use data binding with jack but it still has limitations

Google will add support for Java 8 language features directly into the
current javac and dx set of tools, and deprecate the Jack toolchain.
Check this out , Future of Java 8 Language Feature Support on Android
https://android-developers.googleblog.com/2017/03/future-of-java-8-language-feature.html
Updates:
Java 8 language features are now supported by the Android build system
Yesterday, we released Android Studio 2.4 Preview 6. Java 8 language
features are now supported by the Android build system in the javac/dx
compilation path. Android Studio's Gradle plugin now desugars Java 8
class files to Java 7-compatible class files, so you can use lambdas,
method references and other features of Java 8.
Source : https://android-developers.googleblog.com/2017/04/java-8-language-features-support-update.html

As of gradle:2.2.0-alpha5, Jack builds are not yet compatible with DataBinding.
If you want to use data binding with Java 8, you can use retrolambda.

Related

Kotlin plug-in adds kotlin-stdlib by default

In many android projects, I observed this kotin stdlib dependency being added in the Gradle files. I also observed kotlin and kotlin-android plugin also adds it by default.
I am assuming adding it manually can be avoided? Or is there a downside to it?
org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}
Also, I believe
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
compileOptions can be safely dropped from 100% kotlin application.
Using kotlinOptions.jvmTarget="11" is there a downside to it, in terms of byte-code generation and byte-code compatibility with other jdk versions.
I am assuming adding it manually can be avoided? Or is there a
downside to it?
https://kotlinlang.org/docs/gradle.html#dependency-on-the-standard-library
There's no downside to it, if you want to add it manually and donot want it to be downloaded by the plugin - set this plugin kotlin.stdlib.default.dependency=false property false in gradle.properties file.
Using kotlinOptions.jvmTarget="11" is there a downside to it, in terms
of byte-code generation and byte-code compatibility with other jdk
versions.
It require AGP 7.0+ to desugar apps for API levels 29 and earlier, while targeting jvmVersion to 8 only requires AGP 3.0+.
Otherwise, byte-code is same.
compileOptions can be safely dropped from 100% kotlin application.
Android projects are not 100% Kotlin, there are generated files like BuildConfig.java.
compileOptions should be there, it can be avoided in 100% Kotlin module.

Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8

As per mentioned in developer.android website
"The Jack toolchain is deprecated, as per this announcement. If your
project depends on Jack, you should migrate to using Java 8 support
built into Android Studio’s default toolchain."
I need to use lambda expressions so I have disabled the jack options, but when I compile my code, I get the following error
Error:Jack is required to support Java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8.
Below is the screenshot of my build.gradle file
Check you version of com.android.tools.build:gradle.
I had the same error. My solution:
set com.android.tools.build:gradle:3.0.0-alpha6
update kotlin to 1.1.3-2
add to repositories google()
I'm using AS 3.0 Canary 6.
You should do the following:
Update your Android Studio to version 3.0.1.
Upgrade your gradle to 'com.android.tools.build:gradle:3.0.1'
Make sure you buildToolsVersion is at least 26.0.2.
After that you can remove Jack options and use supported Java 8 features.

Android Studio Lambda expressions are not allowed at this language level

I am working on a chat application. I got a demo app from github, the chat app that is working. In some classes they used lambda expressions but it's working fine, but when I copy those code mine is giving this error " Lambda expressions are not allowed at this language level ". Some people said that android studio does not support lambda expressions but the demo app is working on my phone.
in build.gradle there should be
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
And you should probably use RetroLambda. Look at the demo project's build.gradle file
In their Android project they are using RetroLambda -
a plugin that allows lambdas in lower versions of Java,
which includes Android (see the plugin at the top --> https://github.com/NaikSoftware/StompProtocolAndroid/blob/master/example-client/build.gradle)
Follow the setup here: https://github.com/evant/gradle-retrolambda

Does Java 8 work on Android api 24 and above Or you can use in lower api?

In android, based on this page Java 8 Languages Features, does android work only in API 24 and above, or you can use in API lower than API 24, and if you can use these features, which most miniature version of API in android support these features
Update:
Beginning with Android Studio 2.4, the Jack compiler will be deprecated and Java 8 Support will be integrated in the default build chain. Some Java 8 features are available on any API level, some are still limited to API >= 24, see:
https://developer.android.com/studio/preview/features/java8-support.html
Old answer:
The Java 8 features are available beginning from API level 9, but only if you use Android Studio 2.1 (preview) and the Android N Preview SDK
http://android-developers.blogspot.de/2016/03/first-preview-of-android-n-developer.html
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.
Update
The Jack toolchain is deprecated. Java8 features are coming to the standard toolchain if you use the android plugin version 2.4.0-alpha4 (or higher). More info here.
Original answer
The Java 8 features are available on API N and newer with exception of lambdas. Lambdas are back-ported (using anonymous classes) back to Gingerbread.
The Android N 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 this you need Android Studio 2.1 preview, JDK 8 installed and the latest build tools.
Example build config:
android {
compileSdkVersion 23
buildToolsVersion "24.0.0 rc1"
defaultConfig {
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Update
Starting with Android Studio 2.4, the Jack compiler will be deprecated.
Android Studio 3.0 and later supports all Java 7 language features and a subset of Java 8 language features that vary by platform version.
All info in the official doc:
https://developer.android.com/studio/write/java8-support
You can also configure it directly in the corresponding build.gradle file:
Just configure:
android {
...
// Configure only for each module that uses Java 8
// language features (either in its source code or
// through dependencies).
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// For Kotlin projects
kotlinOptions {
jvmTarget = "1.8"
}
}

What does the language level setting in android studio 0.3.2 Do?

In the latest release of Android Studio (0.4.2), a new setting has been added when creating a new project, namely Language Level
I want to know what that refers to, and the consequence of selecting any of the provided options.
The doc doesn't give me a clear picture of this and i don't want to select an option when i don't know what that will result in?
Thanks
It's about what Java language level you want to use. KitKat supports full Java 7, Gingerbread and up support Java 6 and older versions are Java 5. At least when it comes to the core Java APIs. Roughly the same setting is mentioned here.
You can often use language features that were added in one version in an older version if the compiler knows how to do it. For example the Diamond Operator was added in Java 7 but you can still use that feature in Java 6 since
List<String> list = new ArrayList<>();
actually compiles into the same thing as
List<String> list = new ArrayList<String>();
did.
The "try with resource" construct on the other hand can't be compiled into legal Java 6 compatible code and is therefore exclusive to Apps that require KitKat and up.
The answer can be phrased better, IMHO. The docs are clear about Java 7 and below.
This setting affects which Java language features you can use in your source code.
All Java language features that you use will be compiled so that the code will work in all Android versions, except for the "try with resources" language feature.
From the docs: "If you want to use try with resources, you will need to also use a minSdkVersion of 19. You also need to make sure that Gradle is using version 1.7 or later of the JDK. (And version 0.6.1 or later of the Android Gradle plugin.)"
Java 7 support was added at build tools 19. You can use now features like the diamond operator, multi-catch, try-with-resources, strings in switches, etc. Add the folowing to your build.gradle.
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
Gradle 1.7+, Android gradle plugin 0.6.+ are required.
Note, that only try with resources require minSdkVersion 19. Other features works on previous platforms.

Categories

Resources