encrypted-datastore icon indicating copy to clipboard operation
encrypted-datastore copied to clipboard

InvalidProtocolBufferException (Protocol message contained an invalid tag (zero))

Open YassinELhadedy opened this issue 2 years ago • 8 comments

app crash due to "androidx.security:security-crypto" that u internally use . i know this crash something related to google security-crypto library . but when I figure out for a solution I found many developers recommend to downgrade to ecurity-crypto:1.1.0-alpha01 , so does yr library support alpha versions or if u have any idea to solve this ?

thanks

error log...

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.app, PID: 2511
    java.lang.RuntimeException: Unable to create application com.app.MainApplication: com.google.crypto.tink.shaded.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6790)
        at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2134)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7898)
        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.ArrayDecoders.decodeUnknownField(ArrayDecoders.java:1036)
        at com.google.crypto.tink.shaded.protobuf.ArrayDecoders.decodeUnknownField(ArrayDecoders.java:1028)
        at com.google.crypto.tink.shaded.protobuf.ArrayDecoders.decodeUnknownField(ArrayDecoders.java:1028)
        at com.google.crypto.tink.shaded.protobuf.ArrayDecoders.decodeUnknownField(ArrayDecoders.java:1028)
        at com.google.crypto.tink.shaded.protobuf.MessageSchema.parseProto3Message(MessageSchema.java:5426)
        at com.google.crypto.tink.shaded.protobuf.MessageSchema.mergeFrom(MessageSchema.java:5442)
        at com.google.crypto.tink.shaded.protobuf.ArrayDecoders.decodeMessageField(ArrayDecoders.java:246)
        at com.google.crypto.tink.shaded.protobuf.ArrayDecoders.decodeMessageList(ArrayDecoders.java:704)
        at com.google.crypto.tink.shaded.protobuf.MessageSchema.parseProto3Message(MessageSchema.java:5373)
        at com.google.crypto.tink.shaded.protobuf.MessageSchema.mergeFrom(MessageSchema.java:5442)
        at com.google.crypto.tink.shaded.protobuf.GeneratedMessageLite.parsePartialFrom(GeneratedMessageLite.java:1567)
        at com.google.crypto.tink.shaded.protobuf.GeneratedMessageLite.parseFrom(GeneratedMessageLite.java:1680)
        at com.google.crypto.tink.proto.Keyset.parseFrom(Keyset.java:958)
        at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.read(SharedPrefKeysetReader.java:84)
        at com.google.crypto.tink.CleartextKeysetHandle.read(CleartextKeysetHandle.java:61)
        at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.read(AndroidKeysetManager.java:332)
        at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewKeyset(AndroidKeysetManager.java:288)

YassinELhadedy avatar Jun 14 '23 10:06 YassinELhadedy

What version of security-crypto you use now? You can check it using command:

./gradlew :app:dependencyInsight --dependency security-crypro --configuration releaseRuntimeClasspath

(remember to replace app with your app module name and releaseRuntime with your build variant)

osipxd avatar Jun 15 '23 14:06 osipxd

currently, we only use "io.github.osipxd:security-crypto-datastore-preferences", version.ref = "1.0.0-beta01" is yr latest version.

YassinELhadedy avatar Jun 16 '23 10:06 YassinELhadedy

This library uses security-crypto:1.0.0, but it is possible that any of other libraries uses higher version of security-crypto. Please run this command, to see version of androidx security-crypto:

./gradlew :app:dependencyInsight --dependency androidx.security:security-crypro --configuration productionDebugRuntimeClasspath

Problem: In version catalog libs, version reference '1.0.0.beta01' doesn't exist.

Maybe you've declared version.ref="1.0.0-beta01" instead of version="1.0.0-beta01" in your version catalog? Also, dependencyInsight may be incompatible with configuration on demand. Consider adding --no-configure-on-demand flag

osipxd avatar Jun 20 '23 07:06 osipxd

command result : ./gradlew :app:dependencyInsight --dependency androidx.security:security-crypro --configuration productionDebugRuntimeClasspath --no-configure-on-demand

Configure project :core:base Unzip jar to /Users/yelhadedy/StudioProjects/android-app/core/base/build/hidden-secrets-tmp

Task :app:dependencyInsight No dependencies matching given input were found in configuration ':app:productionDebugRuntimeClasspath'

BUILD SUCCESSFUL in 2s

YassinELhadedy avatar Jun 20 '23 10:06 YassinELhadedy

yes, i 've used

datastoreEncrypted = "1.0.0-beta01"

{ module = "io.github.osipxd:security-crypto-datastore-preferences", version.ref = "datastoreEncrypted" }

YassinELhadedy avatar Jun 20 '23 10:06 YassinELhadedy

Hm.. it looks like only this library uses security-ctypto. Can you create minimal reproducible example for the issue?

osipxd avatar Jun 21 '23 11:06 osipxd

issue tracked

and happened in Android 13 Pixel 4 but ,it does not happen if we did a “Force stop” from the app “App info” menu and does not do a fresh install and just build the app form Android studio without uninstalling the app on device.

i think it's solved in new androidx.security:security-crypto:1.1.0-alpha06 that uses com.google.crypto.tink:tink-android:1.8.0 suggestion

I think crypto:1.1.0-alpha06 solve some issue related to tink

YassinELhadedy avatar Jun 21 '23 15:06 YassinELhadedy

So if I understood you correctly, I can do nothing on the library side to fix this issue? Can I close this issue?

osipxd avatar Dec 02 '23 19:12 osipxd

Fell free to reopen the issue if you find any circumstances related to the library

osipxd avatar Feb 08 '24 15:02 osipxd