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
Related
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.
I am trying to add Firebase Analytics and Firebase Messaging in my Unity App.
I am using Latest official package for Firebase and Unity 2017.4.0f1
After importing Firebase when I try to make a build it fails with the following error
Dex: Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
I have search every where but I am not able to find a solution, people have solved this on Android Studio but I am not able to solve on on Unity. I am not sure how to fix it.
Please help, it will be highly appreciated.
Same question, but with unity 5.6.6.
I have tried create custom mainTemplate.gradle and add this code to "andrond" section and "buildscript" section
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
But it's not helps.
I have found solution! Little dirty, but works.
1) I have used tool JarCheck http://mindprod.com/products1.html#JARCHECK
and found, what problem in com.google.auto.value.auto-value-annotations-1.6.jar (it built for java 1.8), all other libs is 1.7.
This jar added into build by PlayServicesResolver for Firebase.
2) Disable "Auto resolution" in Assets->Play Service Resolver->Android resolver->settings.
3) Delete com.google.auto.value.auto-value-annotations-1.6.jar from "Assets\Plugins\Android\". Firebase looks working ok without this lib.
But now this should be deleted manually after every manual resolution of GP.
In my case..
I updated firebase from 5.3 to 5.5 and the same problem occurred with unity 5.6.5f1
Check this..
https://github.com/firebase/quickstart-unity/issues/321
I updated Google play game service plugin from 0.9.5 to 0.9.62
and solved
After adding a third party library I got the PARSE ERROR: unsupported class file version 52.0 after including the dependency. I have found similar questions like this one. The solution in the link provide suggest to include in the gradle file the following:
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
The problem is that the dependency is using 1.8. So, I have tried to use 1.8 for the entire project by adding Jack as it is suggested here. However, I am also using Realm that can't be used with java 8 as it is explained here.
Is there any way to use 1.8 only for the dependency I want to include and use 1.7 in the rest of the project?
I am quite new and I don't know if this is possible. I have checked around, but I haven't found anything.
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.
I moved my android app over to Android Studio without switching to Gradle. Now I want to move to Gradle. The app compiles in Android Studio before switching to Gradle, but now that I have Gradle all set up, it won't compile the String Switch Statements or the diamond operators. The error I am getting is
Gradle: error: strings in switch are not supported in -source 1.6
(use -source 7 or higher to enable strings in switch)
I have made sure that I am running on JRE 7 by printing the
System.getProperty("java.version")
in a task. The output is
1.7.0_25
What confuses me most is the discrepancy between "-source 1.6" and "use -source 7". But I know that both of these are names for Java sdk's so maybe the titles are just being mixed up.
Is there a Gradle setting I need to set? or is this not possible in Gradle? If not it is confusing why it works without Gradle.
It should be noted that the without Gradle version of my project runs the default Android Studio build. I didn't write an ant script or maven script for building it. One of those may be the way it is being built, but I don't have any project specific files for them. Just the Android Studio .iml files.
UPDATE
I tried adding the following to the build.gradle android{} section
compileOptions {
sourceCompatibility = org.gradle.api.JavaVersion.VERSION_1_7
targetCompatibility = org.gradle.api.JavaVersion.VERSION_1_7
}
but the .class files failed to build and it weren't included in the apk. See the "Android Projects Need Libraries Compiled with Java 1.6" section on this post
You can upgrade an existing Android app/library module to Java 7 by adding the following in the android section of your build.gradle:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
For a Java (non-android) module, you should add the following to build.gradle just after apply plugin: 'java':
sourceCompatibility = 1.7
targetCompatibility = 1.7
For both types of modules, you will need to manually change the language level of your project in File -> Project Structure -> Project (or you can manually edit the config in .idea/misc.xml from JDK_1_6 to JDK_1_7).
You might also need to add the following to .idea/compiler.xml, in the <component name="CompilerConfiguration"> block (but see how you get on without it first):
<bytecodeTargetLevel target="1.7" />