构建失败的android room&eventbus

syqv5f0l  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(338)

我接管了一个android项目,我需要修改数据库(至少添加实体和dao)。问题是,只要代码有一点变化,项目就不再“编译”,我就会得到以下错误。


***\app\src\main\java\fr\***\***\syxs\core\App.java:25: error: cannot find symbol

import fr.***.***.syxs.EventBusIndex;
                                ^
  symbol:   class EventBusIndex
  location: package fr.***.***.syxs

eventbusindex类没有生成,因此,我的应用程序不会编译。我想当我在appdatabase类中更改某些内容时,什么都不会失效/更新?
示例:此代码编译(默认代码)

@Database(entities = {
        MessageInbox.class,
        MessageOutbox.class,
        MessagePredefined.class},
        version = 12)
public abstract class AppDatabase extends RoomDatabase {

    public abstract MessageOutboxDao messageOutboxDao();

    public abstract MessageInboxDao messageInboxDao();

    public abstract MessagePredefinedDao messagePredefinedDao();

    ...

这个不行

@Database(entities = {
        MessageInbox.class,
        MessageOutbox.class,
        MessagePredefined.class},
        version = 12)
public abstract class AppDatabase extends RoomDatabase {

    public abstract MessageOutboxDao messageOutboxDao();

    public abstract MessageInboxDao messageInboxDao();

    public abstract MessagePredefinedDao messagePredefinedDao();

    public abstract OtherClassDao foo();

    ...

无论我多么努力地改变数据库的版本,它都不会改变任何东西。我从我的项目中删除了所有的示意图,我试图清理这里和那里。我还在androidstudio上尝试了著名的“失效缓存&重启”,当然没有结果。我在网上到处找,但找不到任何确凿的证据。
构建.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'org.sonarqube'

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    signingConfigs {
        release {
            storeFile file('C:\\SIGNED\\keystore.jks')
            storePassword '***'
            keyAlias '***'
            keyPassword '***'
        }
        debug {
            storeFile file('C:\\SIGNED\\keystore.jks')
            storePassword '***'
            keyPassword '***'
            keyAlias '***'
        }
    }
    compileSdkVersion 29
    defaultConfig {
        applicationId "fr.***.***"
        minSdkVersion 19
        targetSdkVersion 29
        multiDexEnabled true
        versionCode 37 
        versionName "2.5.8"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString(),
                             eventBusIndex : 'fr.***.***.syxs.EventBusIndex']
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false //true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            multiDexEnabled true
            debuggable true
        }
        debug {
            signingConfig signingConfigs.debug
            multiDexEnabled true
        }
    }
    buildToolsVersion '28.0.3'
    buildFeatures {
        viewBinding = true
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

dependencies {
    // TODO check this
    implementation 'commons-net:commons-net:20030805.205232'

    // TODO delete all implementation of com.android.support.*
    def lifecycleVersion   = "1.1.1"
    def roomVersion        = "2.2.5"
    def multidexVersion    = "2.0.1"
    def eventbusVersion    = "3.2.0"

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "androidx.multidex:multidex:$multidexVersion"
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
    implementation 'org.jetbrains:annotations-java5:20.1.0'

    // ViewModel and LiveData components
    implementation "android.arch.lifecycle:extensions:$lifecycleVersion"
    annotationProcessor "android.arch.lifecycle:compiler:$lifecycleVersion"

    // Room components
    implementation "androidx.room:room-runtime:$roomVersion"
    annotationProcessor "androidx.room:room-compiler:$roomVersion"

    // SocketIO
    implementation 'com.github.nkzawa:socket.io-client:0.6.0'

    // Gson
    implementation 'com.google.code.gson:gson:2.8.6'

    // Sygic
    implementation 'com.sygic.driving:driving-lib:1.2.1'
    implementation 'com.google.android.material:material:1.2.1'
    implementation project(path: ':SygicLib')

    // SFTP
    implementation 'com.jcraft:jsch:0.1.55'

    // EventBus
    implementation "org.greenrobot:eventbus:$eventbusVersion"
    annotationProcessor "org.greenrobot:eventbus-annotation-processor:$eventbusVersion"

    // Test
    testImplementation 'junit:junit:4.13.1'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

sonarqube {
    properties {
     ***
    }
}

repositories {
    mavenCentral()
}

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

我错过了什么?
编辑12/04:
在我的代码中进行了几次更改之后,我注意到问题是根据dao的内容出现的。当它为空时,所有的东西都会编译,但是如果我添加一个方法,编译就会失败。最后,我认为问题更多的是在实体/dao的层次上,但我不知道问题在哪里。
应用程序数据库:

...
public abstract FooDao fooDao();
...

福岛:

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Update;
import androidx.room.Delete;
import androidx.room.Query;

@Dao
public interface FooDao {

    @Insert
    void insert(Foo foo);

    @Update
    void update(Foo foo);

    @Delete
    void delete(Foo foo);

    @Query("SELECT * FROM foo_table WHERE id=:id")
    Foo getFooById(int id);
}

foo公司:

import androidx.room.Entity;
import androidx.room.PrimaryKey;

@Entity(tableName = "foo_table")
public class Foo {

    @PrimaryKey(autoGenerate = true)
    private long id;
    private boolean yes;

    public Foo() {}

    public Foo(long id, boolean no) {
        this.id = id;
        this.yes = no;
    }

    public Foo(boolean no) {
        this.yes = no;
    }

    public boolean getYes() {
        return yes;
    }

    public void setYes(boolean yes) {
        this.yes = yes;
    }
}
ozxc1zmp

ozxc1zmp1#

我找到了解决方案,我忘了在appdatabase中声明我的实体。。。mb

相关问题