Can't test with coverage in Android Studio and ObjectBox bacause of "cannot find symbol" compilation errors in auto-generated files
Asked Answered
T

0

6

I'm using Android studio 4.1.1, ObjectBox 3.0.1 and Kotlin 1.5.10.

The tests run nicely when I hit the run button on the test class or run ./gradlew :app-core:test, but when I click on Run X with coverage the tests run through, I'm shown

Project Is out of Date: Project class files are out of date. Would you like to recompile? The refusal to do it will result in incomplete coverage information

If I click on Cancel the coverage report in the background disappears (so I can't read the coverage info, also there is no coverage info left of the code lines in the editor).

If I click OK compilation is started and I get a compilation error in a ObjectBox-generated file SomeEntityCursor:

Error:(14, 49) java: cannot find symbol
  symbol: class SomeEntity

The same is happening in other generated classes (see details below). But bottom line is that the generated code seems to not be able to see my entity class. Noteworthy: the generated code is in the same module as the entity class.

Fyi, SomeEntity simply looks like this:

@Entity
data class SomeEntity(@Id var id: Long = 0, ...)

Strangely, sometimes it manages to compile, but certainly not if I do a Clean project before!

Here is the full output (I'm sorry for the inconsistencies between example package names and the ones in the log, I hope it doesn't make any difference!):

Information:Kotlin: kotlinc-jvm 1.4.32 (JRE 1.8.0_242-release-1644-b3-6915495)
Information:java: Errors occurred while compiling module 'SomeApp.common.common-android'
Information:javac 1.8.0_242-release was used to compile java sources
Information:11/8/21 2:46 PM - Build completed with 21 errors and 3 warnings in 8 s 772 ms
/Users/xxx/Documents/Programming/SomeApp/common/common-android/build/generated/source/kapt/debug/com/somecompany/someapp/common/android/persistence/SomeEntityCursor.java
    Error:Error:line (14)java: cannot find symbol
  symbol: class SomeEntity
    Error:Error:line (34)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntityCursor
    Error:Error:line (44)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntityCursor
    Error:Error:line (16)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntityCursor
    Error:Error:line (18)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntityCursor.Factory
/Users/xxx/Documents/Programming/SomeApp/common/common-android/build/generated/source/kapt/debug/com/somecompany/someapp/common/android/persistence/SomeEntity_.java
    Error:Error:line (15)java: cannot find symbol
  symbol: class SomeEntity
    Error:Error:line (93)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_
    Error:Error:line (23)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_
    Error:Error:line (27)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_
    Error:Error:line (34)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_
    Error:Error:line (37)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_
    Error:Error:line (40)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_
    Error:Error:line (44)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_
    Error:Error:line (50)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_
    Error:Error:line (63)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_
    Error:Error:line (73)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_
    Error:Error:line (78)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_
    Error:Error:line (83)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_
    Error:Error:line (88)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_
    Error:Error:line (95)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_.SomeEntityIdGetter
    Error:Error:line (23)java: cannot find symbol
  symbol:   class SomeEntity
  location: class com.comecompany.someapp.common.android.persistence.SomeEntity_

I couldn't find any info info on the problem on the web, unfortunately, so any hint is appreciated, thanks!

Triatomic answered 8/11, 2021 at 14:15 Comment(6)
Can you try with the latest stable Android Studio release and Android plugin to make sure this isn't a bug in the tooling that was already fixed?Hewlett
I installed a new Android Studio version, created an empty project with updated tools and added module after module. Same problem. But it's noteworthy that the problem starts ONLY when the app module (including all other modules) is added. I have it on GitHub (privately, I can give you access if you want). There are two commits, one where it works and one where it doesn't anymore @Uwe-ObjectBoxTriatomic
OK, have this same message with a simple Kotlin Android project (not for a Java-only Android project). But if I always click OK the coverage report stays visible. Not sure how to fix this, yet (and if this is even an issue with our tooling).Hewlett
Could you create a bug report for that? You have a simple project to reproduce the problem. If not, can you upload it somewhere so I can reference it and create the bug report? @Uwe-ObjectBoxTriatomic
The problem in my case is also that if not properly recompiled, the coverage report is not showing any numbers in the respective module, btw.Triatomic
I used github.com/objectbox/objectbox-examples/tree/main/… and added a simple unit test to it.Hewlett

© 2022 - 2024 — McMap. All rights reserved.