2

enter image description here

If I do this in code: val x = R.id.x - it will have value like 32123123412.

If I evaluate expression/add to variables watcher this during debug: R.id.x - it will have value like -123456 and x == R.id.x - will be false. It also means that findViewById<View>(R.id.x) will found nothing, while findViewById<View>(x) - will work just fine during debugging.

For some reason all R values during debug differ from values in code. I found file R.txt in build and it had 32123123412 for R.id.x. But I found no files with -123456.

Where does -123456 comes from? How can I make R.id.x same in code and during debug? This is extremely bad during espresso tests debugging.

UPD: problem occurs only in kotlin files. If I create java file and call it from kotlin and check ids there - it will work fine

UPD2: android.R.id.content works fine even in kotlin

UPD3: if in evaluate expression menu choose java and try to see R.id.X - R - will be unresolved reference, even if package fully specified

UPD4: opened task in kotlin bugtracker https://youtrack.jetbrains.com/issue/KT-42479

Nexen
  • 1,407
  • 3
  • 13
  • 41
  • please check this answer: https://stackoverflow.com/a/6646113/12225996 – Ehsan msz Oct 05 '20 at 14:04
  • 3
    Resource identifiers are NOT STABLE, they are reassigned during each build. You should never keep hard reference to their absolute value, only refer to them using their identifier. – Pawel Oct 05 '20 at 14:05
  • 1
    I'm using references, not absolute values. I updated question with `It also means that findViewById(R.id.x) will found nothing, while findViewById(x) - will work just fine.` – Nexen Oct 05 '20 at 14:17
  • 1
    @Ehsanmsz but that means the problem is even more confusing since `1903226` translates to `1D0A7A` which does not map to PPTTNNNN pattern, if we compare it to the correct value `2131956990` which is `7F1314FE`. Later is from `app`, first if from `library` it seems. Later TT is `13` vs `1D` from first. NNNN is also completely different – Nexen Oct 05 '20 at 14:24

1 Answers1

0

In the end it was a bug with kotlin. Developers acknowledged the issue: https://youtrack.jetbrains.com/issue/KT-42479

Nexen
  • 1,407
  • 3
  • 13
  • 41