Android-Room-Database-Backup icon indicating copy to clipboard operation
Android-Room-Database-Backup copied to clipboard

Protocol message contained an invalid tag (zero).

Open gulabsagevadiya opened this issue 2 years ago • 11 comments

Describe the bug Android 10 Getting this error while backup

Smartphone (please complete the following information):

  • Device: Infinix Smart 5
  • OS: Android 10
  • Version beta9

I got this error on firebase Crashlytics Don't have enough resources to get the exact point of error

gulabsagevadiya avatar May 25 '22 02:05 gulabsagevadiya

Hi @gulabsagevadiya without furhter information i cannot help you. I will close this

rafi0101 avatar Jun 09 '22 15:06 rafi0101

Hi @gulabsagevadiya without furhter information i cannot help you. I will close this

Caused by ea.z: Protocol message contained an invalid tag (zero).
       at com.google.crypto.tink.shaded.protobuf.GeneratedMessageLite.parsePartialFrom(GeneratedMessageLite.java:7)
       at com.google.crypto.tink.proto.Keyset.parseFrom(Keyset.java:2)
       at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.read(SharedPrefKeysetReader.java:2)
       at com.google.crypto.tink.CleartextKeysetHandle.read(CleartextKeysetHandle.java:2)
       at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.read(AndroidKeysetManager.java:2)
       at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewKeyset(AndroidKeysetManager.java:2)
       at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:13)
       at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:12)
       at de.raphaelebner.roomdatabasebackup.core.RoomBackup.initRoomBackup(RoomBackup.java:12)
       at de.raphaelebner.roomdatabasebackup.core.RoomBackup.backup(RoomBackup.java:14)
       at com.syst.tuitionapp2.utils.MasterUtilsKt.saveBackUp(MasterUtilsKt.java:14)
       at com.syst.tuitionapp2.newUi.main.DashboardActivity$saveBackUpCall$1.invoke(DashboardActivity.java:14)
       at com.syst.tuitionapp2.newUi.main.DashboardActivity$saveBackUpCall$1.invoke(DashboardActivity.java:14)
       at com.syst.tuitionapp2.utils.ViewUtilsKt.showDynamicViewDialog(ViewUtilsKt.java:38)
       at com.syst.tuitionapp2.newUi.main.DashboardActivity.saveBackUpCall(DashboardActivity.java:23)
       at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1476)
       at android.app.Activity.performResume(Activity.java:8441)
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:5200)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:5269)
       at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:54)
       at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8663)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

gulabsagevadiya avatar Jun 09 '22 16:06 gulabsagevadiya

Already tried with the new version: beta10?

Can you show me the options you pass wenn calling the backup function

rafi0101 avatar Jun 10 '22 08:06 rafi0101

fun Context.saveBackUp(backup: RoomBackup, database: MainDatabase, onComplete: (Boolean, String) -> Unit) {
    val number = sharePrefHelper.user?.key!!
    val newFile = File(this.getExternalFilesDir(null), "tufeeBackup.db")
    backup.database(database)
        .backupIsEncrypted(false)
        .backupLocation(RoomBackup.BACKUP_FILE_LOCATION_CUSTOM_FILE)
        .backupLocationCustomFile(newFile)
        .apply {
            onCompleteListener { success, message, _ ->
                    onComplete(success, message)
            }
        }
        .backup()
}

Here it is how I have used this function

gulabsagevadiya avatar Jun 10 '22 17:06 gulabsagevadiya

Already tried with the new version: beta10?

Can you show me the options you pass wenn calling the backup function

Yes I have used beta10 on the last update still getting this crash

gulabsagevadiya avatar Jun 13 '22 03:06 gulabsagevadiya

Hi @gulabsagevadiya, sorry for my late reply. I see your newFile is from ExternalFilesDir. In this case you could use RoomBackup.BACKUP_FILE_LOCATION_EXTERNAL as backupLocation and pass with customBackupFileName your custom filename Or am I wrong?

rafi0101 avatar Nov 05 '22 12:11 rafi0101

Sure I will try this out

gulabsagevadiya avatar Nov 05 '22 13:11 gulabsagevadiya

First off, thanks for creating such a useful tool and sharing it on Github!

Unfortunately, I am also getting this error now. I have been using beta11 but reverted to beta10 to see if that would fix things. Sadly, it didn't.

One major change in my code that I can think of, is I recently updated the primary key of my database. I use .fallbackToDestructiveMigration() during development that deletes the old database data to avoid schema conflicts but the backup of the new database fails with this error.

Reverting everything and attempting to restore the previous working database also fails with this error.

Clearing the Storage and Cache, also did not fix the error.

I hope this helps shed some additional light on the error.

private RoomBackup roomBackup;
roomBackup = new RoomBackup(sharedObject.getMainActivity());
roomBackup.database(db);
roomBackup.backupLocation(RoomBackup.BACKUP_FILE_LOCATION_EXTERNAL);
roomBackup.customBackupFileName(fileName);
roomBackup.customRestoreDialogTitle("Choose file to restore");
roomBackup.maxFileCount(5);
roomBackup.onCompleteListener((success, message, exitCode) -> {
            Log.d(TAG, "success: " + success + ", message: " + message + ", exitCode: " + exitCode);
            if (success) {
                sharedObject.messageNotification("Otaku Toshokan", "Download from Google Drive complete!");
                sharedObject.restartApp(app.getBaseContext());
                //roomBackup.restartApp(new Intent(sharedObject.getMainActivity(), sharedObject.getMainActivity().getClass()));
            }
        });
2023-01-15 07:56:10.532 19971-19971/com.kyosake.otakutoshokan E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.kyosake.otakutoshokan, PID: 19971
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:558)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 
     Caused by: com.google.crypto.tink.shaded.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
        at com.google.crypto.tink.shaded.protobuf.GeneratedMessageLite.parsePartialFrom(GeneratedMessageLite.java:1566)
        at com.google.crypto.tink.shaded.protobuf.GeneratedMessageLite.parseFrom(GeneratedMessageLite.java:1664)
        at com.google.crypto.tink.proto.Keyset.parseFrom(Keyset.java:957)
        at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.read(SharedPrefKeysetReader.java:84)
        at com.google.crypto.tink.CleartextKeysetHandle.read(CleartextKeysetHandle.java:58)
        at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.read(AndroidKeysetManager.java:328)
        at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewKeyset(AndroidKeysetManager.java:287)
        at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:238)
        at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:155)
        at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:120)
        at de.raphaelebner.roomdatabasebackup.core.RoomBackup.initRoomBackup(RoomBackup.kt:294)
        at de.raphaelebner.roomdatabasebackup.core.RoomBackup.restore(RoomBackup.kt:480)
        at com.kyosake.otakutoshokan.tools.books.BookRepository.restore_state03(BookRepository.java:229)
        at com.kyosake.otakutoshokan.tools.books.BookRepository.lambda$restore_state02$15$com-kyosake-otakutoshokan-tools-books-BookRepository(BookRepository.java:212)
        at com.kyosake.otakutoshokan.tools.books.BookRepository$$ExternalSyntheticLambda1.onSuccess(Unknown Source:4)
        at com.google.android.gms.tasks.zzm.run(com.google.android.gms:play-services-tasks@@18.0.2:1)
        at android.os.Handler.handleCallback(Handler.java:942)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7872)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 

cutnop avatar Jan 15 '23 13:01 cutnop

I have created short extension in kotlin which is very simple to use

here are they

fun Context.getLocalBackUpFile(): File {
    openOrCreateDatabase(MainDatabase.db_name,MODE_PRIVATE,null).execSQL("pragma wal_checkpoint(full)")
    val newFile =File(filesDir,MainDatabase.db_name)
    getDatabasePath(MainDatabase.db_name).copyTo(newFile,true)
    return newFile
}

fun Context.restoreBackUp(file: File) {
    file.copyTo(getDatabasePath(MainDatabase.db_name),true)
    file.delete()
}

gulabsagevadiya avatar Jan 17 '23 06:01 gulabsagevadiya

Thanks for your feedback! I'm sorry, I realized that I'm really bad at debugging my own application....

I can't reproduce the problem on my end unfortunately

rafi0101 avatar Feb 01 '23 20:02 rafi0101

The same thing happens to me, but the strangest thing is that on my work computer it works but not on mine, it gives me the same error

PortgasDLalo1 avatar Jun 18 '23 19:06 PortgasDLalo1