skip to Main Content

Since my last build upgrade, the syntax highlighting in my DAOs is not working anymore.
enter image description here

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:
enter image description here

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


  1. Don’t use alpha version of room in gradle. Use stable version only.
    I was using alpha version of room:

    implementation 'androidx.room:room-ktx:2.5.0-alpha02'
    implementation 'androidx.room:room-common:2.5.0-alpha02'
    kapt 'androidx.room:room-compiler:2.5.0-alpha02'
    androidTestImplementation 'androidx.room:room-testing:2.5.0-alpha02'
    

    When I migrated to stable version it resolved the issue.

    implementation 'androidx.room:room-ktx:2.4.3'
    implementation 'androidx.room:room-common:2.4.3'
    kapt 'androidx.room:room-compiler:2.4.3'
    androidTestImplementation 'androidx.room:room-testing:2.4.3'
    
    Login or Signup to reply.
  2. 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)

    Login or Signup to reply.
  3. 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:

    1. Go to Settings > Editor > Language Injections

    2. Add a new injection of type "Generic Kotlin"

    3. Choose "RoomSQL" as the ID for the injection.

    4. 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!

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search