Ошибки компиляции при использовании библиотеки персистентности помещения в проекте kotlin - PullRequest
0 голосов
/ 07 июня 2018

Я уже несколько дней сталкиваюсь с проблемой.Я разрабатываю приложение, используя Kotlin и библиотеку постоянства комнат.Моя база данных состоит из 4 объектов.Проблема в том, что всякий раз, когда я добавляю kapt "android.arch.persistence.room:compiler:$room_version" независимо от версии комнаты, я получаю следующие ошибки и предупреждения компиляции:

C:\Users\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jre7\1.2.0\ec8b969e26fbcf2265a4d1a1539c4d1d4c5af380\kotlin-stdlib-jre7-1.2.0.jar: kotlin-stdlib-jre7 is deprecated. Please use kotlin-stdlib-jdk7 instead	

C:\Users\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jre8\1.2.0\505f55b9619bbc5f5e26c77427dd24a6a441eef1\kotlin-stdlib-jre8-1.2.0.jar: kotlin-stdlib-jre8 is deprecated. Please use kotlin-stdlib-jdk8 instead	

C:\Users\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jre7\1.2.0\ec8b969e26fbcf2265a4d1a1539c4d1d4c5af380\kotlin-stdlib-jre7-1.2.0.jar: kotlin-stdlib-jre7 is deprecated. Please use kotlin-stdlib-jdk7 instead	

C:\Users\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jre8\1.2.0\505f55b9619bbc5f5e26c77427dd24a6a441eef1\kotlin-stdlib-jre8-1.2.0.jar: kotlin-stdlib-jre8 is deprecated. Please use kotlin-stdlib-jdk8 instead	

C:/Users/Desktop/Meals_App	
app/build/tmp/kapt3/stubs/debug/appDatabase/appDao.java	
error: cannot find symbol
    public abstract java.util.List<appDatabase.recipesEntity> getAll();
                                              ^
  symbol:   class recipesEntity
  location: class appDatabase	

error: cannot find symbol
    appDatabase.recipesEntity recipes);
               ^
  symbol:   class recipesEntity
  location: class appDatabase	

error: cannot find symbol
    appDatabase.chefEntity chefs);
               ^
  symbol:   class chefEntity
  location: class appDatabase	

error: cannot find symbol
    appDatabase.recipesEntity recipes);
               ^
  symbol:   class recipesEntity
  location: class appDatabase	
app/build/tmp/kapt3/stubs/debug/appDatabase/appDatabase.java	

error: cannot find symbol
    public abstract appDatabase.appDao appDao();
                               ^
  symbol:   class appDao
  location: class appDatabase	

error: cannot find symbol
@android.arch.persistence.room.Database(entities = {appDatabase.recipesEntity.class, appDatabase.chefEntity.class, appDatabase.stepsEntity.class, appDatabase.ingredientEntity.class}, version = 1, exportSchema = false)
                                                                                                ^
  symbol:   class chefEntity
  location: class appDatabase	

error: cannot find symbol
@android.arch.persistence.room.Database(entities = {appDatabase.recipesEntity.class, appDatabase.chefEntity.class, appDatabase.stepsEntity.class, appDatabase.ingredientEntity.class}, version = 1, exportSchema = false)
                                                                                                                                                             ^
  symbol:   class ingredientEntity
  location: class appDatabase	

error: android.arch.persistence.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 android.arch.persistence.room.RoomDatabase {
                ^	
app/build/tmp/kapt3/stubs/debug/appDatabase/ingredientEntity.java	

error: cannot find symbol
    public final appDatabase.ingredientEntity copy(int ingID, int recipeID, @org.jetbrains.annotations.NotNull()
                            ^
  symbol:   class ingredientEntity
  location: class appDatabase	
app/build/tmp/kapt3/stubs/debug/appDatabase/stepsEntity.java	

error: cannot find symbol
    public final appDatabase.stepsEntity copy(int stepID, int recipeID, @org.jetbrains.annotations.NotNull()
                            ^
  symbol:   class stepsEntity
  location: class appDatabase	
app/build/tmp/kapt3/stubs/debug/appDatabase/recipesEntity.java	

error: cannot find symbol
@android.arch.persistence.room.Entity(tableName = "recipesEntity", foreignKeys = {@android.arch.persistence.room.ForeignKey(entity = appDatabase.chefEntity.class, childColumns = {"chefID"}, onDelete = 5, parentColumns = {"chefID"})})
                                                                                                                                                ^
  symbol:   class chefEntity
  location: class appDatabase	

error: android.arch.persistence.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 recipesEntity {
             ^	
app/build/tmp/kapt3/stubs/debug/appDatabase/chefEntity.java	

error: android.arch.persistence.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 chefEntity {
             ^	

Вот мои классы базы данных: ChefEntity.kt

@Entity(tableName = "chefEntity", indices = [(Index(value = ("username"), unique = true))])

data class chefEntity(
        @PrimaryKey(autoGenerate = true)
        @ColumnInfo(name = "chef_id")
        var chefID: Int,

        @ColumnInfo(name = "firstname")
        var firstname: String,

        @ColumnInfo(name = "lastname")
        var lastname: String,

        @ColumnInfo(name = "username")
        var username: String,

        @ColumnInfo(name = "password")
        var password: String,

        @ColumnInfo(name = "address")
        var address: String,

        @ColumnInfo(name = "mobile")
        var mobile: String,

        @ColumnInfo(name = "bg_color")
        var bg_color: Int
 )

recipesEntity.kt

@Entity(tableName = "recipesEntity",
        foreignKeys = [(ForeignKey(entity = chefEntity::class,
                parentColumns = [("chefID")],
                childColumns = [("chefID")],
                onDelete = ForeignKey.CASCADE))])

data class recipesEntity(
        @PrimaryKey(autoGenerate = true)
        @ColumnInfo(name = "recipeID")
        val recipeID: Int,

        @ColumnInfo(name = "chef_id")
        val chefID: Int,

        @ColumnInfo(name = "name")
        val name: String,

        @ColumnInfo(name = "prep_time")
        val pTime: String,

        @ColumnInfo(name = "image_name")
        val imageName: String
)

ингредиент Entity.kt

@Entity(tableName = "ingredientEntity",
        foreignKeys = [(ForeignKey(entity = recipesEntity::class,
                parentColumns = [("recipeID")],
                childColumns = [("recipeID")],
                onDelete = ForeignKey.CASCADE))])

data class ingredientEntity(
        @PrimaryKey(autoGenerate = true)
        @ColumnInfo(name = "ingredient_id")
        var ingID: Int,

        @ColumnInfo(name = "recipeID")
        var recipeID: Int,

        @ColumnInfo(name = "ingredient_name")
        var name: String
)

stepsEntity.kt

@Entity(tableName = "stepsEntity",
        foreignKeys = [(ForeignKey(entity = recipesEntity::class,
                parentColumns = [("recipeID")],
                childColumns = [("recipeID")],
                onDelete = ForeignKey.CASCADE))])

data class stepsEntity(
        @PrimaryKey()
        @ColumnInfo(name = "step_id")
        val stepID: Int,

        @ColumnInfo(name = "recipeID")
        val recipeID: Int,

        @ColumnInfo(name = "desciption")
        val desciption: String,

        @ColumnInfo(name = "order")
        val order: Int
)

база данных приложений

@Database(entities = [(recipesEntity::class), (chefEntity::class), (stepsEntity::class), (ingredientEntity::class)],
        version = 1, exportSchema = false)

abstract class appDatabase : RoomDatabase() {
    abstract fun appDao(): appDao
}

appDao

@Dao
interface appDao {

    @Query("SELECT * from recipesEntity")
    fun getAll(): List<recipesEntity>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(recipes: recipesEntity)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(chefs: chefEntity)

    @Update
    fun update(recipes: recipesEntity)

    @Query("DELETE from recipesEntity")
    fun deleteAll()

}

Модуль: приложение

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: "kotlin-kapt"

apply plugin: 'kotlin-android-extensions'


android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.sawsan.mealsapp"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.android.tools.build:gradle:3.1.2'
    implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.41"
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.pes.materialcolorpicker:library:1.2.0'
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
    implementation 'com.afollestad.material-dialogs:commons:0.9.6.0'

    //Room

    def room_version = "1.1.1-rc1" // or, for latest rc, use "1.1.1-rc1"

    implementation "android.arch.persistence.room:runtime:$room_version"
    annotationProcessor "android.arch.persistence.room:compiler:$room_version"
    kapt "android.arch.persistence.room:compiler:$room_version"

    // Extensions = ViewModel + LiveData
    implementation "android.arch.lifecycle:extensions:1.1.1"
    kapt "android.arch.lifecycle:compiler:1.1.1"

    //RxJava support for Room
    implementation "android.arch.persistence.room:rxjava2:$room_version"

    //RxJava
    implementation "io.reactivex.rxjava2:rxkotlin:2.1.0"
    implementation "io.reactivex.rxjava2:rxjava:2.1.3"
    implementation "io.reactivex.rxjava2:rxandroid:2.0.1"
}

Я надеюсь, что кто-то может помочь мне решить эту проблему, так как я не смог найти аналогичного случая в Интернете.Извините, что так долго, и заранее спасибо.

1 Ответ

0 голосов
/ 09 июля 2018

У меня была эта проблема, убедитесь, что расширение ваших файлов правильное, например, у меня был файл с именем AccreditationLogo, а не AccreditationLogo.kt.Казалось, это странно мешает компилятору.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...