Does anybody here still Kotlin Synthetic extension...
# android
c
Does anybody here still Kotlin Synthetic extensions to access views or has everyone shifted to viewbinding? Like if someone had old projects, how did you go around migrating them?
e
Personally, I wouldn’t bother migrating old projects, with Jetpack Compose coming up. We use ViewBinding for new projects though.
s
it really depends on them removing access to kotlin-android-extensions while using newer versions of plugins like AGP, hard to be sure if this will be forced
c
@solidogen I know about this. I was looking for some practical exp. Since old projects can be huge with their structure totally different.
@Ernestas Firstly, I like your Todo picture. Secondly, I was thinking the same, my only concern being if we update to newer Kotlin versions, will it keep on supporting the old extensions or not?
e
@Chetan Tuteja Thanks :). That’s actually a good question, I haven’t seen any mentions of the synthetics support being dropped from newer versions, but I’ll have to investigate. We’re currently using the newest Kotlin version if that’s what you’re asking with kotlin synthetics all over the codebase.
s
synthetics obviously work at the moment
but you can’t really tell what will come in the future, if you don’t have many screens, I would migrate
c
I do have many screens honestly. They are full fledged client apps already launched. That's my only fear currently. For newer projects, yes sure, one can shift to viewbinding, but for old projects, this is a too much disadvantage I feel
@Ernestas I am currently on Kotlin Version 1.4.21 just because of this fear, that if I update the Plugin version, maybe the old projects using synthetics will stop working. What version are you on and does it show deprecation warning or what?
s
kotlin-android-extensions which contains synthetic support is atm deprecated, but it works
tbh there is nothing to be really afraid of, since viewbinding is a generated class, so you already have compile-time safety. you can migrate a single screen and see how much work it is
if you use fragments, you can use 1-liner for viewbinding reference
this shows usage
c
I have used viewBinding, we work with single activity multiple fragments structure here and the way our base is created, it uses Base abstract classes which have functionalities. So for the old projects, which would let's say have at least 50 screens and some of it will be listings via recycler views and include layouts and stuff, migration is not a simple thing for those.
e
1.4.31 I think, it looks like the android team was planning to remove the synthetics plugin from new kotlin versions sometime at the end of this year: https://android-developers.googleblog.com/2020/11/the-future-of-kotlin-android-extensions.html?m=1 (last paragraph)
c
@solidogen I went through it in past, didn't understand it. Still don't. I have basic understanding of Delegates like for using string formatting or some other similar purposes. But a lot of this code goes over my head. The thing is I want to understand it before I use it. Don't want to go in blind.
s
most of this just makes sure you pass the fragment into the method, so it can unsubscribe listening to it’s lifecycle, otherwise delegate wouldn’t be really needed I guess
c
@Ernestas I wonder how people will large scale applications built using synthetics would react to it. I mean migration won't be easy. I guess they could limit to a Kotlin release maybe? Like before version 1.x.x, it will keep working, if you want new Kotlin features, you have to migrate. Something of this sort.
Copy code
android-kotlin-extensions will be removed in a future Kotlin release during or after September 2021
e
I hope that’s the case, if they completely remove it then that means we have to migrate to viewbinding, and migrate to compose soon after :D
s
I don’t think many people will actually migrate whole apps to compose. Java->Kotlin migration is much more appealing, and yet there are lots of untouched apps. Recreating UI in compose is x times more engaging to do right, and even harder to make sure app looks and behaves exactly as it was
c
Does any of your app currently using viewbinding using include layout with merge tags?
e
@solidogen yeah no, I was talking about my team, definitely not everyone will migrate
s
@Chetan Tuteja I tend to use custom views instead of includes. Merge tags in viewbinding have bugs, I saw a ticket on this on github
c
Could you link me to it? My current base has various include layouts in it, let's say for toolbar and stuff like that to avoid recreating them and I am looking to migrate to viewbinding for future projects. Wondering how to mange it all
there seem to be workarounds but I didn’t test those
c
Yeah I checked it. It just means another view we have to now null out in onDestroy.
k
We are currently in phase of migrating to ViewBinsing.
Kotlin sysnthetics plugin is deprecated and will be dropped from future Kotlin releases.