I'm trying to update an old app from sdk version 28 to 33. Unfortunately the ui tests were working fine with the old sdk while with the new one I keep getting "Unresolved reference" to every resource id in the tests. Even if the resources are correctly loaded in the IDE. Any idea how to solve it?
3 Answers
From: https://developer.android.com/reference/kotlin/android/content/res/Resources
It is likely that your issue is due to:
After Build.VERSION_CODES#R (Released publicly as Android 11 in September 2020), Resources must be obtained by android.app.Activity or android.content.Context created with android.content.Context#createWindowContext(int, Bundle). Application#getResources() may report wrong values in multi-window or on secondary displays.

- 1,262
- 5
- 10
-
I'm using "onView(withId())" from espresso so seems it's a different issue (?) – Filnik Apr 19 '23 at 14:12
I faced the same issue, but later on found out that the IDE which I using Android Studio - Electric Eel(2022.1.1) had certain bugs related to UI previews.
The option I got was to uninstall this version and installed any older but more stabled version than this one.
Found this page which can be helpful in solving such issues, do have a look. LINK - SOLUTION

- 220
- 3
- 11
-
actually I have a different issue. I see the layout preview, I'm just not able to run ui tests – Filnik Apr 19 '23 at 15:03
-
I have awarded you since your suggestion give me the idea on how to solve the issue. Thanks Vishal! – Filnik Apr 20 '23 at 13:55
Updating Android Studio to Android Studio Flamingo an run the automatic steps to update the project did the magic. Probably the issue was related to the fact that the app and ui tests had the same package name.

- 352
- 1
- 12
- 33