25

I have this error popping out in logcat all the time. It always shows after every change of activity. And sometimes, the app disappears and in a second it shows again. There is not any fatal error in logcat, all I see is this:

2020-05-20 11:53:26.422 2940-8484/? E/SQLiteDatabase: Error inserting flex_time=3324000 job_id=-1 period=6650000 source=16 requires_charging=0 preferred_network_type=1 target_class=com.google.android.gms.measurement.PackageMeasurementTaskService user_id=0 target_package=com.google.android.gms tag=Measurement.PackageMeasurementTaskService.UPLOAD_TASK_TAG task_type=0 required_idleness_state=0 service_kind=0 source_version=201516000 persistence_level=1 preferred_charging_state=1 required_network_type=0 runtime=1589968406417 retry_strategy={"maximum_backoff_seconds":{"3600":0},"initial_backoff_seconds":{"30":0},"retry_policy":{"0":0}} last_runtime=0
android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: pending_ops.tag, pending_ops.target_class, pending_ops.target_package, pending_ops.user_id (code 2067 SQLITE_CONSTRAINT_UNIQUE)
    at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
    at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:879)
    at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:790)
    at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:88)
    at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1599)
    at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1468)
    at aplm.a(:com.google.android.gms@201516038@20.15.16 (120406-309763488):76)
    at aplb.a(:com.google.android.gms@201516038@20.15.16 (120406-309763488):173)
    at aplb.a(:com.google.android.gms@201516038@20.15.16 (120406-309763488):21)
    at aplb.a(:com.google.android.gms@201516038@20.15.16 (120406-309763488):167)
    at aphk.run(:com.google.android.gms@201516038@20.15.16 (120406-309763488):8)
    at sob.b(:com.google.android.gms@201516038@20.15.16 (120406-309763488):12)
    at sob.run(:com.google.android.gms@201516038@20.15.16 (120406-309763488):7)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at sub.run(:com.google.android.gms@201516038@20.15.16 (120406-309763488):0)
    at java.lang.Thread.run(Thread.java:919)

But it does not show anywhere to the code is there any solution to it?

Edit: Google libraries:

implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.firebase:firebase-core:17.1.0'
implementation 'com.google.firebase:firebase-database:19.0.0'
implementation 'com.google.firebase:firebase-analytics:17.0.1'
implementation 'com.google.firebase:firebase-perf:19.0.0'
implementation 'com.google.android.gms:play-services-ads:18.1.1'
Adam Knirsch
  • 443
  • 1
  • 6
  • 16
  • Maybe you are inserting data into the database, on activity. And unique key constraint failed because you are adding same data. – Krishna Sony May 20 '20 at 10:07
  • 2
    This seems to be coming from GMS code. What are the versions of google library dependencies in your project? – laalto May 20 '20 at 10:15
  • @KrishnaSony The problem is I do not insert data into database anywhere in the app. I only use one prepopulated database, which I take data from, but I do not even use it in some activities where this error occur. – Adam Knirsch May 20 '20 at 10:16
  • @laalto Added google libraries I use – Adam Knirsch May 20 '20 at 10:25
  • pull db and check data in Db Browser for SQLite – silentsudo May 20 '20 at 10:28
  • @silentsudo And where do I get that database? I do not use in my app any. – Adam Knirsch May 20 '20 at 10:46
  • FIrst consider updating those dependencies. You can find more recent version numbers in https://firebase.google.com/support/release-notes/android#latest_sdk_versions and https://developers.google.com/android/guides/releases – laalto May 20 '20 at 11:18
  • 6
    In my case I use 'com.google.firebase:firebase-analytics:17.4.2' and it causes me the same error. If I delete this dependency from gradle - this error disappears. So the root of the problem is with Firebase I guess. – Ievgen May 28 '20 at 18:02
  • This might be of some use (i guess - it's been open for more than 1 year now).. https://github.com/firebase/firebase-android-sdk/issues/361 – Jay Sidri Jun 23 '20 at 07:13
  • I see this also when there is nothing related to using Room, but when dealing with analytics, but from the traces it is related to Google's gms –  Jun 25 '20 at 22:49
  • I don't think it's related to Firebase because it says SQLite in the log message. – c-an Mar 30 '21 at 06:25

3 Answers3

7

From this issue opened in the firebase-android-sdk project:

Since it requires an update to play services, I'm holding off from giving you a timeline for when this will roll out. But, this would require no action/SDK upgrades from developers and should get fixed on your customer devices automatically.

Gustavo Pagani
  • 6,583
  • 5
  • 40
  • 71
2

i had same issue. my case solved by adding firebase messaging artifactory to module gradle file:

implementation 'com.google.firebase:firebase-messaging:20.2.3'

your case maybe fix by adding missing library.

reza rayatnia
  • 81
  • 1
  • 6
  • I have the below API in gradle. still getting the issue ///firebase implementation platform("com.google.firebase:firebase-bom:$firebase_bom_version") api "com.google.firebase:firebase-core" implementation "com.google.firebase:firebase-messaging" implementation "com.google.firebase:firebase-perf" implementation "com.google.firebase:firebase-appindexing" // App indexing implementation "com.google.firebase:firebase-crashlytics-ktx" implementation "com.google.firebase:firebase-crashlytics" – Rameshbabu May 05 '23 at 06:23
0

I have incorrectly used the following in the "onMessageReceived" method

NotificationManagerCompat notificationManager = ContextCompat
                .getSystemService(this, NotificationManagerCompat.class);

And elsewhere I used the following

NotificationManager notificationManager = ContextCompat
                .getSystemService(this, NotificationManager.class);

By changing the first one like second one, and updating firebase and gsm modules

implementation 'com.google.firebase:firebase-messaging:23.2.0'
implementation 'com.google.firebase:firebase-core:21.1.1'
implementation platform('com.google.firebase:firebase-bom:32.2.0')

// Play Services
implementation "com.google.android.gms:play-services-location:21.0.1"
implementation "com.google.android.gms:play-services-oss-licenses:17.0.1"

the error went away. (I am not sure about play-services-oss-licenses that is related or not.)

C.F.G
  • 817
  • 8
  • 16