Since my last build upgrade, the syntax highlighting in my DAOs is not working anymore.
My expectation (and experience) is, that there is syntax highlighting in the queries and once the database inspector is running, there is also a button on the left side, which executes the SQL statement on the running database.
I don’t know, why this happened. The only thing I did, was run recommended upgrades for my build gradles. Also, reverting these changes did not improve the situation.
At least in regards to syntax highlighting I found a solution:
However, that still does not resolve the problem of "Quick running" the sql statement in the database inspector.
Also to note here, I tried already this: How to highlight SQL syntax of Room Dao in Android Studio, which did not work. In my case, there is no listing for "Android Room SQL", but only "Room SQL".
Any ideas?
3
Answers
Don’t use alpha version of room in gradle. Use stable version only.
I was using alpha version of room:
When I migrated to stable version it resolved the issue.
I have asked same question at issuetracker.google.com: https://issuetracker.google.com/issues/234612964
An intermediate solution is here:
https://issuetracker.google.com/issues/234612964#comment6
Please check that link out, there is a work-around there which works with ‘2.5.0-alpha03’ at least. Haven’t tested it with ‘2.5.0-alpha02’.
There will be a fix for it in Android Studio soon (september/october 2022)
Auto highlighting still doesn’t work with:
Android Studio Electric Eel | 2022.1.1
Build #AI-221.6008.13.2211.9477386, built on January 11, 2023
and
room: 2.5.0
in kotlin @Dao class.
So, as said here, you should:
Go to Settings > Editor > Language Injections
Add a new injection of type "Generic Kotlin"
Choose "RoomSQL" as the ID for the injection.
Add the following for the "Places Patterns":
+ kotlinParameter().ofFunction(0, kotlinFunction().withName("Query").definedInClass("androidx.room.Query"))
+ kotlinParameter().ofFunction(0, kotlinFunction().withName("DatabaseView").definedInClass("androidx.room.DatabaseView"))
And injection works fine!