cfl
cfl

Reputation: 1049

RoomProcessor compilation or a circular dependency

I've been struggling for days with and issue with Android Room component.

All I did was upgrade my Android studio from 3.3 to 3.4.1, this comes with changes to gradle etc that are done. I've even tried going back to 3.3, but nothing is working. I've have run with Run with --info or --debug option to try see more details but nothing gives me more info. Please help

e: /.../app/build/tmp/kapt3/stubs/debug/com/.../model/HotspotEntity.java:7: error: [RoomProcessor:MiscError] androidx.room.RoomProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public final class HotspotEntity implements android.os.Parcelable {
             ^
e: /.../app/build/tmp/kapt3/stubs/debug/com/.../ConditionEntity.java:7: error: [RoomProcessor:MiscError] androidx.room.RoomProcessor "same as above".
public final class ConditionEntity implements android.os.Parcelable {
             ^
e: /.../app/build/tmp/kapt3/stubs/debug/com/.../model/AdLimits.java:6: error: [RoomProcessor:MiscError] androidx.room.RoomProcessor "same as above"
public final class AdLimits {
             ^
e: /.../app/build/tmp/kapt3/stubs/debug/com/.../model/AdTarget.java:6: error: [RoomProcessor:MiscError] androidx.room.RoomProcessor "same as above"
public final class AdTarget {
             ^
e: /.../app/build/tmp/kapt3/stubs/debug/com/.../model/AdUrl.java:6: error: [RoomProcessor:MiscError] androidx.room.RoomProcessor "same as above"
public final class AdUrl {
             ^

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> Compilation error. See log for more details

Versions

Android Gradle:
3.4.1
Gradle version:
5.4.1
Android Room:
def room_version = "2.1.0-alpha06"
implementation 'androidx.room:room-runtime:' + room_version
kapt 'androidx.room:room-compiler:' + room_version
testImplementation 'androidx.room:room-testing:' + room_version

----UPDATE----

Below was tried with room 2.1.0-rc01"which changed it to the same problem but for a different class:

AppDatabase.java:8: error: [RoomProcessor:MiscError] androidx.room.RoomProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public abstract class AppDatabase extends androidx.room.RoomDatabase {

Grade File

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.cfl.surfstoked"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 19
        versionName "1.0.4"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        debug {
            debuggable true
        }

        release {
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    repositories {
        mavenCentral()
    }

    lintOptions {
        checkReleaseBuilds false
    }

    configurations {
        cleanedAnnotations
        compile.exclude group: 'org.jetbrains', module: 'annotations'
    }
}

dependencies {
    kapt 'com.google.dagger:dagger-android-processor:2.23.1'

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.0.2'

    def lifecycleVersion = "2.1.0-alpha02"
    implementation 'androidx.lifecycle:lifecycle-extensions:' + lifecycleVersion
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:' + lifecycleVersion
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-alpha01'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
    kapt 'androidx.lifecycle:lifecycle-compiler:' + lifecycleVersion

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    //DI
    def koinVersion = "1.0.2"
    implementation 'org.koin:koin-android:' + koinVersion
    implementation 'org.koin:koin-androidx-scope:' + koinVersion
    implementation 'org.koin:koin-androidx-viewmodel:' + koinVersion

    //Navigation
//    def navigationVersion = "1.0.0-beta02"
//    implementation 'android.arch.navigation:navigation-fragment-ktx:' + navigationVersion
//    implementation 'android.arch.navigation:navigation-ui-ktx:' + navigationVersion

    def navigationVersion = "2.1.0-alpha01"
    implementation 'androidx.navigation:navigation-fragment-ktx:' + navigationVersion
    implementation 'androidx.navigation:navigation-ui-ktx:' + navigationVersion

    implementation 'org.greenrobot:eventbus:3.1.1'

    //Coroutines
    def corutinesVersion = "1.1.1"
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:' + corutinesVersion
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:' + corutinesVersion

    //Database
    def room_version = "2.1.0-rc01"
    implementation 'androidx.room:room-runtime:' + room_version
    kapt 'androidx.room:room-compiler:' + room_version
//    implementation 'androidx.room:room-coroutines:' + room_version
    testImplementation 'androidx.room:room-testing:' + room_version

}

apply plugin: 'com.google.gms.google-services'

app dependencies

debugCompileClasspath - Compile classpath for compilation 'debug' (target  (androidJvm)).
+--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:{strictly 1.3.30} -> 1.3.30 (c)
+--- org.jetbrains.kotlin:kotlin-stdlib:{strictly 1.3.30} -> 1.3.30 (c)
+--- org.jetbrains.kotlin:kotlin-stdlib-common:{strictly 1.3.30} -> 1.3.30 (c)
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:{strictly 1.3.30} -> 1.3.30 (c)
+--- androidx.core:core-ktx:{strictly 1.0.2} -> 1.0.2 (c)
+--- androidx.annotation:annotation:{strictly 1.1.0-rc01} -> 1.1.0-rc01 (c)
+--- androidx.core:core:{strictly 1.1.0-alpha05} -> 1.1.0-alpha05 (c)
+--- com.google.guava:listenablefuture:{strictly 9999.0-empty-to-avoid-conflict-with-guava} -> 9999.0-empty-to-avoid-conflict-with-guava (c)
+--- androidx.lifecycle:lifecycle-runtime:{strictly 2.2.0-alpha01} -> 2.2.0-alpha01 (c)
+--- androidx.lifecycle:lifecycle-common:{strictly 2.2.0-alpha01} -> 2.2.0-alpha01 (c)
+--- androidx.arch.core:core-common:{strictly 2.1.0-beta01} -> 2.1.0-beta01 (c)
+--- androidx.versionedparcelable:versionedparcelable:{strictly 1.1.0-alpha02} -> 1.1.0-alpha02 (c)
+--- androidx.collection:collection:{strictly 1.1.0-alpha03} -> 1.1.0-alpha03 (c)
+--- androidx.concurrent:concurrent-futures:{strictly 1.0.0-alpha02} -> 1.0.0-alpha02 (c)
+--- androidx.lifecycle:lifecycle-extensions:{strictly 2.2.0-alpha01} -> 2.2.0-alpha01 (c)
+--- androidx.arch.core:core-runtime:{strictly 2.1.0-beta01} -> 2.1.0-beta01 (c)
+--- androidx.fragment:fragment:{strictly 1.1.0-alpha05} -> 1.1.0-alpha05 (c)
+--- androidx.viewpager:viewpager:{strictly 1.0.0} -> 1.0.0 (c)
+--- androidx.customview:customview:{strictly 1.0.0} -> 1.0.0 (c)
+--- androidx.loader:loader:{strictly 1.0.0} -> 1.0.0 (c)
+--- androidx.lifecycle:lifecycle-livedata:{strictly 2.2.0-alpha01} -> 2.2.0-alpha01 (c)
+--- androidx.lifecycle:lifecycle-livedata-core:{strictly 2.2.0-alpha01} -> 2.2.0-alpha01 (c)
+--- androidx.lifecycle:lifecycle-viewmodel:{strictly 2.2.0-alpha01} -> 2.2.0-alpha01 (c)
+--- androidx.activity:activity:{strictly 1.0.0-alpha05} -> 1.0.0-alpha05 (c)
+--- androidx.savedstate:savedstate:{strictly 1.0.0-alpha02} -> 1.0.0-alpha02 (c)
+--- androidx.lifecycle:lifecycle-process:{strictly 2.2.0-alpha01} -> 2.2.0-alpha01 (c)
+--- androidx.lifecycle:lifecycle-service:{strictly 2.2.0-alpha01} -> 2.2.0-alpha01 (c)
+--- androidx.lifecycle:lifecycle-viewmodel-ktx:{strictly 2.1.0-alpha02} -> 2.1.0-alpha02 (c)
+--- org.jetbrains.kotlinx:kotlinx-coroutines-android:{strictly 1.1.1} -> 1.1.1 (c)
+--- org.jetbrains.kotlinx:kotlinx-coroutines-core:{strictly 1.1.1} -> 1.1.1 (c)
+--- org.jetbrains.kotlinx:kotlinx-coroutines-core-common:{strictly 1.1.1} -> 1.1.1 (c)
+--- androidx.appcompat:appcompat:{strictly 1.0.2} -> 1.0.2 (c)
+--- androidx.cursoradapter:cursoradapter:{strictly 1.0.0} -> 1.0.0 (c)
+--- androidx.legacy:legacy-support-core-utils:{strictly 1.0.0} -> 1.0.0 (c)
+--- androidx.documentfile:documentfile:{strictly 1.0.0} -> 1.0.0 (c)
+--- androidx.localbroadcastmanager:localbroadcastmanager:{strictly 1.0.0} -> 1.0.0 (c)
+--- androidx.print:print:{strictly 1.0.0} -> 1.0.0 (c)
...
+--- androidx.room:room-runtime:{strictly 2.1.0-rc01} -> 2.1.0-rc01 (c)
+--- androidx.room:room-common:{strictly 2.1.0-rc01} -> 2.1.0-rc01 (c)
+--- androidx.sqlite:sqlite-framework:{strictly 2.0.1} -> 2.0.1 (c)
+--- androidx.sqlite:sqlite:{strictly 2.0.1} -> 2.0.1 (c)
+--- com.jakewharton.timber:timber:{strictly 4.7.1} -> 4.7.1 (c)
+--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.3.30
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.30
|         \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.30
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.30
...
+--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1 (*)
+--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1 (*)
+--- androidx.room:room-runtime:2.1.0-rc01
|    +--- androidx.room:room-common:2.1.0-rc01
|    |    \--- androidx.annotation:annotation:1.1.0-rc01
|    +--- androidx.sqlite:sqlite-framework:2.0.1
|    |    +--- androidx.annotation:annotation:1.0.2 -> 1.1.0-rc01
|    |    \--- androidx.sqlite:sqlite:2.0.1
|    |         \--- androidx.annotation:annotation:1.0.2 -> 1.1.0-rc01
|    +--- androidx.sqlite:sqlite:2.0.1 (*)
|    +--- androidx.arch.core:core-runtime:2.0.1 -> 2.1.0-beta01 (*)
|    +--- androidx.core:core:1.0.0 -> 1.1.0-alpha05 (*)
|    \--- androidx.collection:collection:1.0.0 -> 1.1.0-alpha03 (*)

Upvotes: 11

Views: 5439

Answers (10)

Marco Hernaiz
Marco Hernaiz

Reputation: 5888

You must include the library:

implementation org.jetbrains:annotations-java5:19.0.0

Because the code which is generated out of the annotations through the kapt plugin, uses org.jetbrains.annotations.NotNull annotation.

It you copy-paste the generated java class is your classpath, you will see the compilation error.

Cheers

Upvotes: 1

Waldmann
Waldmann

Reputation: 1817

Had same issue. Occured after I fetched project from my github.
Dependencies/versions changes had no effect.
What i did is deleted all branches on GitHub except the primary one, and created new project from the remaining branch.
Issue is gone out of the box.

Upvotes: 0

tialawllol
tialawllol

Reputation: 35

Had kinda the same issue and the following annotations exclusions under dependencies (don't know why anymore)

configurations {
    compile.exclude group: 'org.jetbrains', module: 'annotations'
}

Removed it and it worked. Maybe that helps you?

Upvotes: 1

Ch4vi
Ch4vi

Reputation: 402

I had the same problem and I could fix it just updating the DB version:

@Database(
    entities = [...],
    version = 4, exportSchema = true
)

The problem is because the autogenerated schemas, another solution could be deleting your old schemas in schemas folder in your project but can cause a bit of trouble if your app is in production.

Upvotes: 1

mtotschnig
mtotschnig

Reputation: 1511

I had run into the same problem, and comparing the OP's gradle file with mine, I found that both contained

configurations {
    cleanedAnnotations
    compile.exclude group: 'org.jetbrains', module: 'annotations'
}

By removing it, Room's annotation processing started to work.

Upvotes: 2

moritz_original
moritz_original

Reputation: 545

For all those can't compile here is a little (hopefully temporary) workarround.

If you switch back the gradle version to 3.3.2 android studio should compile a usual and you can leave all other dependencies as they are or update them.

That setup works for me:

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.0'
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.9.0"
        classpath 'io.fabric.tools:gradle:1.+'
    }

Upvotes: 1

Joel
Joel

Reputation: 838

Let's consider trying the following:

Remove any room related dependencies with these ones, which are the latest ones per: The Room Documentation

implementation 'androidx.room:room-common:2.1.0'
implementation 'androidx.room:room-compiler:2.1.0'
implementation 'androidx.room:room-runtime:2.1.0'

Second thing to consider is that you are duplicating dependencies with different versions, you might get issues when the build system tries to perform its dependency resolution and lead to misleading errors, for example:

   implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha01'
   implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'

One should be enough, preferably the stable one.

If you need information about dependencies and migrating some to androidx as well here is the migrating to androidx guide

Upvotes: 1

tynn
tynn

Reputation: 39853

You commented out the room-coroutines dependency, but I'd assume you didn't change your actual implementation. This dependency was not removed, but rather renamed to room-ktx. So just add it to enable the Coroutine support for Room.

implementation 'androidx.room:room-ktx:' + room_version

Upvotes: 1

Prokash Sarkar
Prokash Sarkar

Reputation: 11873

From the initial lookup some of your dependencies are old. Please try the following setup ran and tested by me.

Android Studio : 3.4.1

build.gradle (project)

dependencies {
    classpath 'com.android.tools.build:gradle:3.4.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31"
    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0-alpha05"
    classpath 'com.google.gms:google-services:4.2.0'
}

build.gradle (app)

android {
    compileSdkVersion 29
    defaultConfig {
        targetSdkVersion 29
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    kapt 'com.google.dagger:dagger-android-processor:2.23.1'

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31"
    implementation 'androidx.core:core-ktx:1.0.2'

    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-alpha01'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha01'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-alpha01'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
    kapt 'androidx.lifecycle:lifecycle-compiler:2.2.0-alpha01'

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    //DI
    implementation 'org.koin:koin-android:1.0.2'
    implementation 'org.koin:koin-androidx-scope:1.0.2'
    implementation 'org.koin:koin-androidx-viewmodel:1.0.2'

    implementation 'org.greenrobot:eventbus:3.1.1'

    //Coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'

    //Database
    implementation 'androidx.room:room-runtime:2.1.0'
    kapt 'androidx.room:room-compiler:2.1.0'
    testImplementation 'androidx.room:room-testing:2.1.0'
}

Upvotes: 4

TheAnkush
TheAnkush

Reputation: 915

Try Updating room version to "2.1.0-rc01".

def room_version = "2.1.0-rc01"

Upvotes: 0

Related Questions