java.lang.ClassNotFoundException: MainActivity


I’ve started a new project with Ionic6 and Capacitor 4. I’ve built it with Angular code and it works flawlessly on browser. So, I’ve added Android and iOS platforms without issues (apparently). I’ve followed all guides to execute prompt commands correctly and in the correct order. Lastly I’ve executed:

ionic capacitor build android

the whole thing built correctly and Android Studio opened (version Android Studio Dolphin | 2021.3.1 Patch 1). BUT! bad news starts here… as soon as I try to build the app with Android Studio, immediately the following error appears:

“/Applications/Android” -javaagent:/Applications/Android -Dfile.encoding=UTF-8 MainActivity
Errore: impossibile trovare o caricare la classe principale MainActivity
Causato da: java.lang.ClassNotFoundException: MainActivity

Process finished with exit code 1"

What the heck? MainActivity class is present, is exactly as Capacitor 4.0 requires.

So I’ve tried to update build configuration to verify MainActivity path. Inside the congifuration form, MainActivity is shown in red and if I try to browse and pick that class manually, It does recognize it and the “ok” button remains grayed. Why?

Can someone enlighten me why it happens?

I’m using a Mac mini M1, with the latest version of Mac OS (13.0.1).

Thank you!