I started diving into AOSP development recently and I am following some code labs originally written in Java on how to customize the SystemUI (for Automotive AOSP).
I have checked that parts of CarSystemUI are now using Kotlin, and I wanted to redo this code lab.
I followed the tutorial and added the codelab_layout.xml
. I then updated the sysui_overlay_window.xml
and added this ViewStub
:
<ViewStub android:id="@+id/codelab_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout="@layout/codelab_layout"/>
Which declares the codelab_stub
id.
The puzzle is that in the next step I am supposed to add a view controller. In Java the code lab asks to add:
@SysUISingleton
public class CodeLabViewControllerJava extends OverlayViewController {
@Inject
public CodeLabViewControllerJava(
OverlayViewGlobalStateController overlayViewGlobalStateController) {
super(R.id.codelab_stub, overlayViewGlobalStateController);
}
}
which compiles just fine. However, if I add a view controller in Kotlin like:
@SysUISingleton
class CodeLabViewControllerKotlin @Inject constructor(
overlayViewGlobalStateController: OverlayViewGlobalStateController
) : OverlayViewController(R.id.codelab_stub, overlayViewGlobalStateController)
I get the following compilation error:
CodeLabViewControllerKotlin.kt:12:32: error: unresolved reference: codelab_stub
) : OverlayViewController(R.id.codelab_stub, overlayViewGlobalStateController) {
^
which is baffling to me, since the Java code compiles without any problem.
Any idea why this is happening?
PS: If I replace R.id.codelab_stub
with a hardcoded Int
, the Kotlin code compiles fine.