question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Kotlin synthetic caching not working in library artifact

See original GitHub issue

I’ve created a self-contained project using groupie where I checked that seems the caching of the kotlin synthetic views seems not being used whatsover . if you look at the code

class GroupieDummyModel(val content: String = "Hello World") : Item() {
    override fun bind(viewHolder: ViewHolder, position: Int) {
        viewHolder.textView.text = content
    }
    override fun getLayout(): Int = R.layout.item_content
}

It will produce the following bytecode

   public void bind(@NotNull ViewHolder viewHolder, int position) {
      Intrinsics.checkParameterIsNotNull(viewHolder, "viewHolder");
      TextView var10000 = (TextView)((LayoutContainer)viewHolder).getContainerView().findViewById(id.textView);
      Intrinsics.checkExpressionValueIsNotNull(var10000, "viewHolder.textView");
      var10000.setText((CharSequence)this.content);
   }

which it stills use findViewById and not findViewByCache since Item doesn’t implements LayoutContainer doesn’t really matter that ViewHolder implements its Ithink, the Kotlin Compiler doesn´t know about that because it really expects the Item implementing it so it doesn´t generate the caching bytecode, seems like doing this is the same as not using LayoutContainer whatsover since it stills make the lookup in the hole itemView tree view.

Or maybe I’m really missing something here

Project: https://gitlab.com/leobrujah/kotlin-synthetic-test/blob/master/app/src/main/java/com/test/kotlinsyntheticssample/MainActivity.kt

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
lisawraycommented, Dec 4, 2018

I opened an issue with the Kotlin team: https://youtrack.jetbrains.com/issue/KT-28617

2reactions
lisawraycommented, Dec 4, 2018

OK, bizarre. It’s happening only with the published library…

If you go in https://github.com/lisawray/groupie/blob/master/example/build.gradle and change the dependency to the library module rather than the published library

    implementation project(':library-kotlin-android-extensions')
//    implementation 'com.xwray:groupie-kotlin-android-extensions:2.2.1'

Then you see any Item (say CardItem) using findCachedViewById. If you do the reverse, it uses findViewById.

Read more comments on GitHub >

github_iconTop Results From Across the Web

import kotlinx.android.synthetic.main.activity_main is not working
So the problem as I have found is in gradle plugins, then you need to restart, rebuild your project. Share.
Read more >
Migrating to Apollo Kotlin 3.0 - Apollo GraphQL Docs
To quickly reach a working state, follow the steps below. Once you have a working app, we strongly recommend to migrate to idiomatic...
Read more >
Navigation | Android Developers
The navigation-testing artifact now has a dependency on the Kotlin standard library. The API has been changed to be more consistent with Kotlin ......
Read more >
What's new in Kotlin 1.6.0
Kotlin 1.6.0 introduces new language features, optimizations and improvements to existing features, and a lot of improvements to the Kotlin ...
Read more >
Kotlin 1.2.20 is out - The JetBrains Blog
Build caching for Kotlin annotation processors is disabled by ... As usual, if you run into any problems with the new release, you're ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found