No data when upgrading from CBL 2.7.1 to 2.8.0 (Android)

Setup

CBL Android 2.7.1 & 2.8.0
Android Studio 4.1

Reproducible steps

  • install my app on device
  • check if data is displayed
  • update 2.7.1 to 2.8.0 in gradle file in Android Studio, click “Sync Now”
  • install/update
  • no data is displayed in my app
  • add new data -> new data is displayed. Old data is not

I also observed that there is a folder with this path: /data/data/com.my.app/files/couchbase_database.cblite2 when installing my app with CBL 2.7.1. It’s still there after upgrading to 2.8.0. But there were no file changes. Though the folder is missing when doing a fresh install with CBL 2.8.0.

My hunch is that the database was moved to a different path. Could it be because of this change ?

This was tested on two smartphones, both running Android 10.

1 Like

What happens if you specify the DatabaseConfiguration.setDirectory(folderPath)?

database-configuration class ref

wondering if database is corrupted when upgrade happened?

Is" data" defined as existing attachments?

I’ve done some more digging! This code

DatabaseConfiguration configuration = new DatabaseConfiguration();
database = new Database(DATABASE_NAME, configuration);
Log.d(TAG, "database path = " + database.getPath());

prints
D/CouchbaseUtil: database path = /data/data/com.my.app/files/.couchbase/couchbase_database.cblite2/

in all three cases. The cases are:

  • only 2.7.1
  • upgrade from 2.7.1 to 2.8.0
  • only 2.8.0

Since the path is the same I don’t know where 2.8.0 stores the data.

@sridevi.saragadam When upgrading to 2.8.0, there’s no data, and adding data is displayed and persisted. The timestamps of the files in /data/data/com.my.app/files/.couchbase/couchbase_database.cblite2/ do not update. Hence there are no changes in these files. That’s why I think the database is not corrupted but in a different path altogether.

@jayahari.vavachan
Using this code

DatabaseConfiguration configuration = new DatabaseConfiguration();
configuration.setDirectory("/data/data/com.my.app/files/.couchbase/couchbase_database.cblite2/");
database = new Database(DATABASE_NAME, configuration);

has the same effect. No data is displayed.

@Richard_Lewis I’m upgrading from 2.7.1 to 2.8.0. Not from 1.x to 2.8.0. By data I meant documents and blobs and the whole database.

I was trying to get an open source project from Couchbase showcasing CBL to work but failed as the projects are many years old and Android, Android Studio and Gradle changed quite a bit. In particular this repository: https://github.com/couchbaselabs/userprofile-couchbase-mobile-android#standalone-branch

Is there any open source demo project showcasing CBL with 2.7 which I can upgrade to 2.8 and check if the database is gone there, too?

That project is compatible with CBL 2.7 , You may have to upgrade gradle but it will work with 2.7

I can confirm the issue with this repository: https://github.com/couchbaselabs/userprofile-couchbase-mobile-android#standalone-branch

Since getting the project up-to-date was not trivial I attached it: CouchbaseUserProfile.zip (3.2 MB)

Please note that the entered data will be displayed after upgrading CBL if - and only if - this line is present:

config.setDirectory(String.format("%s/%s", context.getFilesDir(), username)); // in class DatabaseManager, line 58

If not the data won’t be displayed.

The starter code in 2.7 does not specify a path, too. 2.7 https://docs.couchbase.com/couchbase-lite/2.7/java-android.html

For this reason I must believe that I won’t be the only one running into the issue. The issue being that all data is gone?!

1 Like

This is a bug. The good news is that the data is neither corrupted nor destroyed.

Databases have always been stored at: [root directory]/[database name].cblite. The default for [root directory] is context.getFilesDir for Android and whatever directory the JVM was started in, for Java.

In an attempt to deal with upcoming changes in the way Android handles file-system access, I changed the default root directory to be context.getFilesDir + “/.couchbase”. The new release is looking for your database in a directory that does not exist. (or, if you attempt to downgrade, in a the parent of the directory that actually contains the database)

@benjamin_glatzeder has nearly the correct workaround. You need code like this:

   final DatabaseConfiguration config = new DatabaseConfiguration();
   config.setDirectory(context.getFilesDir().getAbsolutePath());

We are discussing ways of addressing this.

2 Likes

@benjamin_glatzeder Please pick up 2.8.1 which includes fix for this issue. You should be able to upgrade from 2.7.x to 2.8.1 with no issues.

2 Likes