I take over an Android project and I need to modify the database (at least add entities and daos). The problem is that at the slightest change in the code, the project doesn't 'compile' anymore and I get the following error.
***\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
The EventBusIndex class is not generated and so, my app won't compile. I think when i change somethings in my AppDatabase class, nothing is invalidated/updated ?
An example : This code compiles (default code)
@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();
...
This one don't
@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();
...
No matter how hard I try to change the version of the database, it doesn't change anything. I removed all the schematics from my project, I tried to clean up here and there. I also tried the famous 'Invalidate cache & restart' on AndroidStudio, without results of course. I looked all over the net but I couldn't find anything conclusive.
build.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'
}
What did I miss ?
Edit 12/04:
After several changes in my code, I noticed that the problem appears according to the content of my dao. When it's empty everything compiles, but if I add even one method, the compilation fails. Finally, I think the issue is more at the level of my entity/dao, but I don't know where the problem lies.
AppDatabase :
...
public abstract FooDao 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;
}
}
I found the solution, I forgot to declare my entity in AppDatabase ... mb