5

I want to try out Room Persistence library, but after adding and downloading it with gradle, I can find most classes, except:

import android.arch.persistence.room.Database;
import android.arch.persistence.room.RoomDatabase;

import com.doors.geopoly.dal.entities.User;

@Database(entities = {User.class}, version = 1)

public abstract class GeoDatabase extends RoomDatabase {
    public abstract UserDao userDao();
}

Every room library class is present, except RoomDatabase will be red in the IDE stating that it can't resolve that symbol.

Why?

Here's my gradle config:

project(":core") {
    apply plugin: "java"


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"

        implementation "android.arch.persistence.room:runtime:1.1.1"
        annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
    }
}
user3156850
  • 85
  • 1
  • 7

2 Answers2

0

It seems that you separated layers like Clean Architecture.

if we suppose that you use a separated module for wrapping all of db transactions and so on that named db_module

You should note that Room is an Android Library that are lifecycleAware and depend on Android platform, so you must define your db_module - that contain Room - as an Android library.

so it's just using

apply plugin: "com.android.library"

instead of

apply plugin: "java"

this changes your java module to a android module that contain Android OS properties.

beigirad
  • 4,986
  • 2
  • 29
  • 52
0

For some reason, I had the same error as the OP, with no suggestion offered.

To fix, I had to manually create the import:

import androidx.room.RoomDatabase;
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253