How can I use newer release of android databinding library? - android

according to the bintray, newer version of the Android Databinding library has been released(1.0-rc5).
but if I'm correct, only compiler, compilerCommon and baseLibrary are updated, and dataBinder(which we actually include in build.gradle) is still 1.0-rc4.
Is there a way to use newer compiler, compilerCommon and baseLibrary while using dataBinder 1.0-rc4? Or is there already a 1.0-rc5 for dataBinder?

You can override the data-binding version in the build.gradle, like this:
dataBinding {
enabled true
version '1.1'
}

Never mind, in Android gradle plugin 1.5.0-beta1, dev team integrated data binding plugin into android plugin.
http://tools.android.com/tech-docs/new-build-system

Related

What's the difference between the Kotlin and the Gradle version setting and IDE?

I'm wondering if the difference of the kotlin version between gradle setting and ide.
I can see the kotlin version of IDE(Tools -> Kotlin -> Configure Kotlin).
And there is another Kotlin version defined in build.gradle.
I want to know the difference.
I think that the version in buidl.gradle affects to real project and some dependencies.
And the version in IDE affects when we write the code.
Is my guess right?
IDE kotlin version help live coding style i.e. you get kotlin suggestion in that version.
Gradle kotlin version is your project version i.e. it compile your code on that version.
These version may be different. Your IDE kotlin version may be updated than your gradle kotlin version.

Getting weird bugs when trying to update to Kotlin 1.4.0. How to make it work with Gradle and IntelliJ IDEA 2020.2.1?

Kotlin 1.4.0 is stable now. Therefor, I wanted to update my multi module Android project to use it. I set IDEA to use Kotlin plugin 1.4.0-release-IJ2020.2-1 and in my buildSrc build.gradle.kts using Kotlin DSL, I'm loading Kotlin for the jvm like this:
plugins {
kotlin("jvm") version "1.4.0"
}
My app level plugins block looks like this
plugins {
id("com.android.application")
id("com.google.gms.google-services")
kotlin("android")
kotlin("kapt")
id("kotlin-android-extensions")
id("androidx.navigation.safeargs.kotlin")
}
I have also added the Kotlin stdlib to my app level build.gradle.kts dependencies
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.4.0")
When trying to build my project now, I get multiple Errors like the following:
'let((T) -> R): R' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3
I don't understand. How is gradle trying to use Kotlin 1.3 here? Any idea on how to fix this? Its working fine when using Kotlin v1.3.72 instead.
What I tried so far:
Clean Project
Invalidate caches and restart
Delete .gradle folder and restart
Fix broken classes paths
UPDATE
Forgot to mention that I'm also getting the following warning. How is it unsupported when it is stable?
> Configure project :buildSrc
WARNING: Unsupported Kotlin plugin version.
The `embedded-kotlin` and `kotlin-dsl` plugins rely on features of Kotlin `1.3.72` that might work differently than in the requested version `1.4.0`.
Maybe you should add the Kotlin standard lib to your dependencies explicitly?
dependencies {
implementation(kotlin("stdlib"))
}
With Kotlin 1.4 it is no longer required it add this dependency. The plugin applies the Stdlib by default to the projects it is applied to.
From the Kotlin 1.4 release notes:
You no longer need to declare a dependency on the stdlib library in any Kotlin Gradle project, including a multiplatform one. The dependency is added by default.
The automatically added standard library will be the same version of the Kotlin Gradle plugin, since they have the same versioning.

Kotlin version issue

(Kotlin version that is used for building with Gradle (1.2.71) differs from the one bundled into the IDE plugin (1.3.0))
How can I solve this?
In build.gradle, look for kotlin_version or kotlinVersion, and change it from 1.2.71 to 1.3.0 (Note: the version variable could also possibly be defined in another .gradle script in the project, or in gradle.properties, instead of build.gradle).

Androidx and databinding

I'm migrating my dependencies for an Android P test to the androidx dependencies. For some not very clear reasons my project does not compile anymore (and no I won't provide the details to avoid a distinct problem). I found out (via gradlew dependencies) that the databinding uses the "oldschool" dependency android.arch.lifecycle:runtime:1.0.3 instead of androidx.lifecycle:lifecycle-runtime:2.0.0-beta01. I guess that could be one reason.
Any idea how to force using the new package names/dependencies?
I face the similar problem, the Data Binding library use the support library, some classes may conflict with the AndroidX. I have to remove the DataBinding for now.
I just read this release note, it said that this issue had been fixed, but I didn't see the effect.
Enabling AndroidX in the gradle.properties fixed this problem for me:
android.useAndroidX=true
android.enableJetifier=true
See https://developer.android.com/jetpack/androidx#using_androidx:
android.useAndroidX: When set to true, the Android plugin uses the
appropriate AndroidX library instead of a Support Library. The flag is
false by default if it is not specified.
android.enableJetifier: When
set to true, the Android plugin automatically migrates existing
third-party libraries to use AndroidX by rewriting their binaries. The
flag is false by default if it is not specified.
Check Layout files maybe there are Views left which use support library instead of androidx
for example
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
change it to
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
I tried that while I had a weak internet connection, so I skipped to update to Android Studio 3.2. That was my fault. With that upgrade (the unziping took almost an hour no idea why) I was requested also to upgrade my build tools to com.android.tools.build:gradle:3.2.0-beta04 (or whatever is the newest version matching for your Android Studio version (I would not install the 3.3.0-alpha03) and upgraded the gradle wrapper to 4.6.
Now the dependencies are gone and I'm happy.
1- Add this line into build.gradle
android {
dataBinding {
enabled = true
}
}
2- gradle.properties(Project Properties)
android.databinding.enableV2=true
In my case, the error was because the tool to migrate to AndroidX does not work perfectly. There was still some layout files using some old support libraries. After fixing those files, everything went well =)
To fix, every support library that was being used in those layout files, I changed to the right one following this link: https://developer.android.com/jetpack/androidx/migrate

Why must $kotlin_version be explicitly specified in Android?

Supporting Kotlin in an Android studio project requires two dependencies: kotlin-gradle-plugin in Project/build.gradle and kotlin-stdlib-jdk7 in Project/app/build.gradle, and these two need to have the same version. The common method seems to be using a single kotlin_version variable which you then have to manually change when the IDE updates its Kotlin plugin — as of Android Studio 3.1.3, the IDE is still not able to automatically update the dependencies if you use a $variable as the version.
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
In non-Android Kotlin projects i.e. those using apply: 'kotlin' instead of apply plugin: 'kotlin-android', it is possible to simply omit the version from the kotlin-stdlib-jdk7 dependency, which will then be automatically resolved from the plugin.
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7'
This even works on non-Android modules within Android projects. My question is, why is this not possible in Android modules? Why can't the $kotlin_version simply be omitted? If the feature has been present since Kotlin 1.1.2, why is it still causing compile errors on Android even on Kotlin 1.2.51? Or is it actually possible to do this, and if so, how can it be done?
In fact this is not Kotlin specific but has to do with how Gradle manages dependencies.
See https://docs.gradle.org/current/userguide/declaring_dependencies.html on how to specify the version of a dependency in Gradle.
In this case
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
is the standard way of setting the version. As the this version number is the same for several dependency it is declared in a variable in order to make it easy to change the version for all Kotlin libraries.
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7'
Uses dependency constraints which are available since Gradle 4.6. It is used for the same purpose. One can set the version of a library in a central place and this way keep the version at a common value without having to go through all gradle.properties files of a larger project.

Categories

Resources