I'm having some great code which I would like to share with others. I thought it would be a good idea to wrap the sharable code into an Android Library.
I'm using some foreign code, which requires me to specify this in my build.gradle for the library:
compileOptions {
sourceCompatibility '1.8'
targetCompatibility = '1.8'
}
I had a lot of problems to make some functions run, which ran successfully while they were embedded in my old MainActivity. Now, when they were in the lib it always crashed for unrelated and unclear reasons.
Until - and I admit, I don't really understand, what difference this makes - I specified exactly the same compileOptions regarding source and targetCompatibility in my app's build.gradle.
From that moment on all problems where gone.
Does that make any sense to somebody?
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.
How can I define android's compileOptions within codenameone1 project ?
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Thanks in advance
We don't support that at this time. There's an RFE to add this but I can't seem to find it right now in our issue tracker.
This is a bit problematic as integrating the Android builtin Java 8 support somewhat collides with our builtin Java 8 support. I'm assuming you need this to integrate native Android code, the solution for that is rather simple. Wrap it as an AAR library which is self contained and as such should work regardless of our settings.
The solution that works for me was adding this build hint:
android.xgradle_default_config = compileOptions {sourceCompatibility 1.8; targetCompatibility 1.8}
I am using lambda expressions in code for which to support i have added following in the module gradle :
jackOptions {
enabled true
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
But build is taking too much time , more than 10 mins , i tried searching other posts , found this mentioning problems using jack .
So i just wanted to know if anyone's using jackOptions and is able to run/build the project smoothly .
TIA .
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
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.