android:allowBackup="true" inside AndroidManifest.xml prevents the data from being cleared even after the app is uninstalled.
Add this to your manifest:
android:allowBackup="false"
and reinstall the app.
Note: Make sure you change it back to true later on if you want auto backups.
Another solution:
Check the identityHash of your old json file and the new json file in apps\schema folder.
If the identityHash is different, it will give that error. Find out what you have changed by comparing both json files if you don't want to change anything.
Make sure you have exportSchema = true.
@Database(entities = {MyEntity.class, ...}, version = 2, exportSchema = true)
json schema file:
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "53cc5ef34d2ebd33c8518d79d27ed012",
"entities": [
{
code:
private void checkIdentity(SupportSQLiteDatabase db) {
String identityHash = null;
if (hasRoomMasterTable(db)) {
Cursor cursor = db.query(new SimpleSQLiteQuery(RoomMasterTable.READ_QUERY));
//noinspection TryFinallyCanBeTryWithResources
try {
if (cursor.moveToFirst()) {
identityHash = cursor.getString(0);
}
} finally {
cursor.close();
}
}
if (!mIdentityHash.equals(identityHash) && !mLegacyHash.equals(identityHash)) {
throw new IllegalStateException("Room cannot verify the data integrity. Looks like"
+ " you've changed schema but forgot to update the version number. You can"
+ " simply fix this by increasing the version number.");
}
}