Updated 21.06.2015
I wanna try kotlin and android databinding in a same project. But when I add to kotlin-gradle-plugin dependency I cannot build even an empty project anymore with error:
cannot generate view binders java.lang.NoClassDefFoundError: kotlin/jvm/internal/ExtensionFunctionImpl
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0-beta3'
classpath "com.android.databinding:dataBinder:1.0-rc0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:0.12.613"
}
}
Any workaroud to make it work together?
Unfortunately,this is caused by a kotlin version inconsistency between databinding and kotlin plugin.
We'll remove kotlin dependency from the plugin on rc1 but until then you would need to use kotlin 0.11.91.
Also, since kotlin's annotation processor support is limited at this moment and data binding is using annotation processor; they probably won't work well (though I have not tried).
Related
I am an Android Developer and have a general Kotlin question. Does Android Studio support all Kotlin features and APIs? I am certain that all basic types and operators are fully supported and Android Studio can compile. Is it safe to also assume that Functions, Lambdas, Coroutines, etc. are fully supported? For example, when Java 8 support was announced for Android Studio, there was a documentation website explaining which Java 8 features were supported and which were not:
https://developer.android.com/studio/write/java8-support#supported_features
But this does not exist for Kotlin. I'm assuming if it's a line of standard Kotlin code, it will compile in Android Studio, is that correct?
The reason for my question is that I work with a group of Java server (mostly spring boot) and JavaFX developers, and we like to share as much code as possible. The lack of Java 8 compatibility in Android caused some problems for us. We're looking to convert most of our code into Kotlin now. I'd like to assume that all of the standard features:
https://kotlinlang.org/api/latest/jvm/stdlib/index.html
And hopefully all of the coroutines features:
https://kotlinlang.org/docs/reference/coroutines/coroutines-guide.html
Will be fully supported for both let's say an Android app built with Android Studio and a Java desktop app built with IntelliJ.
Within reason, you control the version of Kotlin that gets used and therefore what features are available.
If you have a Kotlin-enabled Android Studio project, and you look in the top-level build.gradle file, you may see code like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.20'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext.kotlin_version = '1.3.20' controls the Kotlin version that you will use for the Kotlin plugin (via the interpolated string in the classpath directive), and similarly for the Kotlin runtime dependency in a module's build.gradle file.
So, a project with the above code can use Kotlin/JVM features that were supported in Kotlin 1.3.20.
The runtime dependency that we use today is org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version. The jdk7 indicates that the runtime does not depend on any Java 8+ stuff that Android lacks.
However, changes in future versions of Kotlin will require you to upgrade the Kotlin version in your project. For example, a project using 1.2.71 might not have access to all Kotlin 1.3 syntax.
Kotlin is fully supported by Android and Android Studio and even advertised on the Android website:
Kotlin is production-ready for your Android app development.
Source
I wanted to update the version of my kotlin plugin to 1.3.10. This is what looks like my build.gradle :
buildscript {
ext.kotlin_version = '1.3.10'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Then i want to define a variable for my kotlin-stdlib :
ext.kotlinDependency = "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
But it does not work for this last line, I have always done this way and it worked well for the 1.2.61 version. Should i just wait before updating the version for the last one ?
As the Kotlin 1.3 compatibility guide says,kotlin-stdlib-jre7 is a deprecated artifact name which has been removed in Kotlin 1.3. kotlin-stdlib-jdk7 is the replacement to be used.
I followed the getting started guide here, I don't want to migrate to androidx at this time so I did:
Made sure I have the correct repositories
Added com.android.support:design:28.0.0-rc01 to my dependencies, since the Getting Started tutorial states this is the only thing needed if I don't want to migrate to androidx.
Made sure compileSdkVersion was 28
Switched to Theme.MaterialComponents.Light.NoActionBar
Downloaded Android P SDK and sources (but not any of the rest that's not on the image):
Made sure I am using AppCompactAtivity
Rebuilt the project
And I still get the error:
The following classes could not be found:
- com.google.android.material.button.MaterialButton
What am I missing?
You should not use com.google.android.material package instead use com.android.support.
In your case android.support.design.button.MaterialButton
I had that problem with Android Studio 3.2 release candidates, both using com.android.support and using com.google.android.material.
I upgraded to the 3.3 canary and that specific problem went away although I now have other (unrelated?) problems (runtime failures to inflate, etc).
I can't find any documentation stating required Android Studio versions for layout editor to work.
Make sure that the repositories section includes Google’s Maven repository google(). For example:
allprojects {
repositories {
google()
allprojects {
repositories {
google()
jcenter()
}
}
Add the library to the dependencies section:
implementation 'com.google.android.material:material:1.0.0'
dependencies {
// ...
implementation 'com.google.android.material:material:1.0.0'
// ...
}
I updated my AS from 3.0 to 3.1. After fixing several issues that showed up with the update, I am stuck at making Kotlin work.
Kotlin code compiles and runs, although I can't edit kotlin files. Kotlin keywords are not recognised by the editor, using kotlin code from java classes appear red and in general I can't really do anything with kotlin.
I use:
buildscript {
ext.kotlin_version = '1.2.41'
...
...
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.google.gms:google-services:3.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
kotlin plugin: 1.2.41-release-Studio3.1-1
and org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version
In gradle I do not use dynamic versions because that could lead to indeterminate builds.
So I state my dependencies like so:
compile 'com.squareup.okhttp:okhttp:2.2.0'
However, how do I find out if there is a new version available and what its number is?
You can use a gradle-versions-plugin to do it. This plugin provides a dependencyUpdates task, which
Displays a report of the project dependencies that are up-to-date, exceed the latest version found, have upgrades, or failed to be resolved.
All you need to do, is to apply, by configuration of build.script dependencies, as:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.ben-manes:gradle-versions-plugin:0.11.3'
// classpath 'org.codehaus.groovy:groovy-backports-compat23:2.3.5' // uncomment if you're using Gradle 1.x
}
}
And applying the plugin itself, with:
apply plugin: 'com.github.ben-manes.versions'
You could use this site to search your library latest version.