aws-amplify / amplify-android

The fastest and easiest way to use AWS from your Android app.
https://docs.amplify.aws/lib/q/platform/android/
Apache License 2.0
247 stars 117 forks source link

Amplify getting started tutorial on Android crashes with SQLiteConstraintException #840

Closed niqo01 closed 3 years ago

niqo01 commented 4 years ago

I am following the Ampligy getting started tutorial for Android https://docs.amplify.aws/start/getting-started/add-api/q/integration/android I am at the "Connect to the Cloud" step 5, and when I run the application, it crashes with:

E/Tutorial: Observation failed.
    AmplifyException {message=Error in saving the model: ModelMetadata[id=318f28da-9d30-42b0-bc9e-505d41f9898f], cause=android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: ModelMetadata.id (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY), recoverySuggestion=See attached exception for details.}
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$save$3$SQLiteStorageAdapter(SQLiteStorageAdapter.java:333)
        at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$lMf-ZzF10cDUtleQzXsLUxpfzAI.run(Unknown Source:12)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
     Caused by: android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: ModelMetadata.id (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY)
        at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
        at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:938)
        at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:790)
        at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:88)
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.saveModel(SQLiteStorageAdapter.java:717)
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$save$3$SQLiteStorageAdapter(SQLiteStorageAdapter.java:315)
        at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$lMf-ZzF10cDUtleQzXsLUxpfzAI.run(Unknown Source:12) 
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:923) 

Find here the project source: tutorial.zip

jamesonwilliams commented 4 years ago

Hi @niqo01! Can you please include:

  1. Your GraphQL schema
  2. Relevant code snippets
  3. The type (and API level) of the device you were running this on
niqo01 commented 4 years ago

Hi @jamesonwilliams,

I am following the AWS tutorial and attached the source in the first message. The GraphQL schema and code snippet are in the tutorial.zip. Just in case, here is the MainActivity from the zip above:

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            TestAmplifyTheme {
                // A surface container using the 'background' color from the theme
                Surface(color = MaterialTheme.colors.background) {
                    Greeting("Android")
                }
            }
        }
        Amplify.DataStore.observe(Todo::class.java,
            { Log.i("Tutorial", "Observation began.") },
            { Log.i("Tutorial", it.item().toString()) },
            { Log.e("Tutorial", "Observation failed.", it) },
            { Log.i("Tutorial", "Observation complete.") }
        )
    }
}

The schema:

enum Priority {
  LOW
  NORMAL
  HIGH
}

type Todo @model {
  id: ID!
  name: String!
  priority: Priority
  description: String
}

I am using the Android emulator, API 30 / Android 11 (Google Play) x86

jamesonwilliams commented 4 years ago

Thanks @niqo01! Sorry, missed the zip file :-).

rjuliano commented 4 years ago

@niqo01 Are you getting this message consistently? I used your project with the emulator settings you provided but I'm unable to reproduce the error. Are there any other steps you're going through?

LynkKid commented 4 years ago

I am also having the same problem, please help me

Jacke-debug commented 4 years ago

Same problem. Have gone through the complete tutorial three times now and it did work once.

raphkim commented 4 years ago

Thank you for reporting this issue. We will add this issue to our sprint board to prioritize.

Switcher05 commented 4 years ago

Well I was going through the tutorial and encountered this issue. https://docs.amplify.aws/start/getting-started/integrate/q/integration/android#create-a-todo Step 3 worked fine, made changes in step 4 and now it's broken. Tried undo and rerun step 3 and it's still failing. Not a good week to be trying to convince my team to use Amplify lol.

10/14 23:43:59: Launching 'app' on Nexus 5X API 29 x86.
$ adb shell am start -n "com.example.todo/com.example.todo.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 20387 on device 'Nexus_5X_API_29_x86 [emulator-5554]'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/om.example.tod: The ClassLoaderContext is a special shared library.
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/Tutorial: Initialized Amplify
W/RenderThread: type=1400 audit(0.0:44): avc: denied { write } for name="property_service" dev="tmpfs" ino=9472 scontext=u:r:untrusted_app:s0:c133,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0 app=com.example.todo
D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
W/om.example.tod: Accessing hidden field Lsun/misc/Unsafe;->theUnsafe:Lsun/misc/Unsafe; (greylist, reflection, allowed)
    Accessing hidden method Lsun/misc/Unsafe;->allocateInstance(Ljava/lang/Class;)Ljava/lang/Object; (greylist, reflection, allowed)
I/amplify:aws-datastore: DataStore orchestrator transitioning states. Current mode = STOPPED, target mode = SYNC_VIA_API.
    Starting to observe local storage changes.
I/amplify:aws-datastore: Now observing local storage. Local changes will be enqueued to mutation outbox.
I/amplify:aws-datastore: Starting API synchronization mode.
W/om.example.tod: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
    Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
I/amplify:aws-datastore: DataStore orchestrator transitioning states. Current mode = LOCAL_ONLY, target mode = SYNC_VIA_API.
I/Tutorial: Observation began.
I/amplify:aws-datastore: DataStore orchestrator transitioning states. Current mode = LOCAL_ONLY, target mode = SYNC_VIA_API.
I/Tutorial: Todo {id=dbd3acc2-52b7-4006-80aa-fec76ce3c2f2, name=Build Android application, priority=null, description=Build an Android application using Amplify}
    Saved item: Build Android application
D/HostConnection: HostConnection::get() New Host Connection established 0xdbb5e190, tid 20425
    HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_1 
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
D/EGL_emulation: eglCreateContext: 0xdbb1a4e0: maj 3 min 1 rcv 4
D/EGL_emulation: eglMakeCurrent: 0xdbb1a4e0: ver 3 1 (tinfo 0xdbb008c0)
E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
    glUtilsParamSize: unknow param 0x000082da
W/Gralloc3: mapper 3.x is not supported
D/HostConnection: createUnique: call
D/HostConnection: HostConnection::get() New Host Connection established 0xdbb5ea50, tid 20425
    HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_1 
D/eglCodecCommon: allocate: Ask for block of size 0x1000
    allocate: ioctl allocate returned offset 0x3ff805000 size 0x2000
D/EGL_emulation: eglMakeCurrent: 0xdbb1a4e0: ver 3 1 (tinfo 0xdbb008c0)
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
W/om.example.tod: Long monitor contention with owner pool-1-thread-2 (20435) at void com.amplifyframework.api.aws.SubscriptionEndpoint.requestSubscription(com.amplifyframework.api.graphql.GraphQLRequest, com.amplifyframework.core.Consumer, com.amplifyframework.core.Consumer, com.amplifyframework.core.Consumer, com.amplifyframework.core.Action)(SubscriptionEndpoint.java:107) waiters=0 in void com.amplifyframework.api.aws.SubscriptionEndpoint.requestSubscription(com.amplifyframework.api.graphql.GraphQLRequest, com.amplifyframework.core.Consumer, com.amplifyframework.core.Consumer, com.amplifyframework.core.Consumer, com.amplifyframework.core.Action) for 749ms
W/om.example.tod: Long monitor contention with owner pool-1-thread-2 (20435) at void com.amplifyframework.api.aws.SubscriptionEndpoint.requestSubscription(com.amplifyframework.api.graphql.GraphQLRequest, com.amplifyframework.core.Consumer, com.amplifyframework.core.Consumer, com.amplifyframework.core.Consumer, com.amplifyframework.core.Action)(SubscriptionEndpoint.java:107) waiters=1 in void com.amplifyframework.api.aws.SubscriptionEndpoint.requestSubscription(com.amplifyframework.api.graphql.GraphQLRequest, com.amplifyframework.core.Consumer, com.amplifyframework.core.Consumer, com.amplifyframework.core.Consumer, com.amplifyframework.core.Action) for 844ms
I/amplify:aws-datastore: Began buffering subscription events for remote mutations [class com.amplifyframework.datastore.generated.model.Todo] to Cloud models of types [ON_CREATE, ON_UPDATE, ON_DELETE].
I/amplify:aws-datastore: Successfully sync'd down model state from cloud.
I/amplify:aws-datastore: Starting processing subscription data buffer.
I/amplify:aws-datastore: Starting API synchronization mode.
I/amplify:aws-datastore: Began buffering subscription events for remote mutations [class com.amplifyframework.datastore.generated.model.Todo] to Cloud models of types [ON_CREATE, ON_UPDATE, ON_DELETE].
I/amplify:aws-datastore: Successfully sync'd down model state from cloud.
I/amplify:aws-datastore: Starting processing subscription data buffer.
    Starting API synchronization mode.
I/amplify:aws-datastore: Began buffering subscription events for remote mutations [class com.amplifyframework.datastore.generated.model.Todo] to Cloud models of types [ON_CREATE, ON_UPDATE, ON_DELETE].
I/amplify:aws-datastore: Successfully sync'd down model state from cloud.
I/amplify:aws-datastore: Starting processing subscription data buffer.
W/System.err: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
I/amplify:aws-datastore: Started processing the mutation outbox. Pending mutations will be published to the cloud.
I/chatty: uid=10133(com.example.todo) RxSingleSchedul identical 1 line
I/amplify:aws-datastore: Started processing the mutation outbox. Pending mutations will be published to the cloud.
I/amplify:aws-datastore: Successfully enqueued PendingMutation{mutatedItem=Todo {id=dbd3acc2-52b7-4006-80aa-fec76ce3c2f2, name=Build Android application, priority=null, description=Build an Android application using Amplify}, classOfMutatedItem=class com.amplifyframework.datastore.generated.model.Todo, mutationType=CREATE, mutationId=aa22b10a-0e98-11eb-964a-ed18bd2ebcd0, predicate=MatchAllQueryPredicate}
I/amplify:aws-datastore: Mutation outbox has pending mutation for dbd3acc2-52b7-4006-80aa-fec76ce3c2f2, refusing to merge.
I/amplify:aws-datastore: Successfully removed from mutations outboxPendingMutation{mutatedItem=Todo {id=dbd3acc2-52b7-4006-80aa-fec76ce3c2f2, name=Build Android application, priority=null, description=Build an Android application using Amplify}, classOfMutatedItem=class com.amplifyframework.datastore.generated.model.Todo, mutationType=CREATE, mutationId=aa22b10a-0e98-11eb-964a-ed18bd2ebcd0, predicate=MatchAllQueryPredicate}
I/Tutorial: Todo {id=dbd3acc2-52b7-4006-80aa-fec76ce3c2f2, name=Build Android application, priority=null, description=Build an Android application using Amplify}
I/Tutorial: Todo {id=dbd3acc2-52b7-4006-80aa-fec76ce3c2f2, name=Build Android application, priority=null, description=Build an Android application using Amplify}
I/Tutorial: Todo {id=dbd3acc2-52b7-4006-80aa-fec76ce3c2f2, name=Build Android application, priority=null, description=Build an Android application using Amplify}
W/amplify:aws-datastore: Storage adapter subscription ended in error
    AmplifyException {message=Error in saving the model: ModelMetadata[id=dbd3acc2-52b7-4006-80aa-fec76ce3c2f2], cause=android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: ModelMetadata.id (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY), recoverySuggestion=See attached exception for details.}
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$save$3$SQLiteStorageAdapter(SQLiteStorageAdapter.java:333)
        at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$JhGtXoPGeJ7lbNvRHxROfLs-WmE.run(Unknown Source:12)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: ModelMetadata.id (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY)
        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 com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.saveModel(SQLiteStorageAdapter.java:717)
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$save$3$SQLiteStorageAdapter(SQLiteStorageAdapter.java:315)
        at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$JhGtXoPGeJ7lbNvRHxROfLs-WmE.run(Unknown Source:12) 
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919) 
E/Tutorial: Observation failed.
    AmplifyException {message=Error in saving the model: ModelMetadata[id=dbd3acc2-52b7-4006-80aa-fec76ce3c2f2], cause=android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: ModelMetadata.id (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY), recoverySuggestion=See attached exception for details.}
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$save$3$SQLiteStorageAdapter(SQLiteStorageAdapter.java:333)
        at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$JhGtXoPGeJ7lbNvRHxROfLs-WmE.run(Unknown Source:12)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: ModelMetadata.id (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY)
        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 com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.saveModel(SQLiteStorageAdapter.java:717)
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$save$3$SQLiteStorageAdapter(SQLiteStorageAdapter.java:315)
        at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$JhGtXoPGeJ7lbNvRHxROfLs-WmE.run(Unknown Source:12) 
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919) 
W/amplify:aws-datastore: Failed to sync remote model into local storage: ModelWithMetadata{model=Todo {id=dbd3acc2-52b7-4006-80aa-fec76ce3c2f2, name=Build Android application, priority=null, description=Build an Android application using Amplify}, syncMetadata=ModelMetadata{id='dbd3acc2-52b7-4006-80aa-fec76ce3c2f2', _deleted=null, _version=1, _lastChangedAt=Temporal.Timestamp{timestamp=1602733442401}}}
    AmplifyException {message=Error in saving the model: ModelMetadata[id=dbd3acc2-52b7-4006-80aa-fec76ce3c2f2], cause=android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: ModelMetadata.id (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY), recoverySuggestion=See attached exception for details.}
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$save$3$SQLiteStorageAdapter(SQLiteStorageAdapter.java:333)
        at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$JhGtXoPGeJ7lbNvRHxROfLs-WmE.run(Unknown Source:12)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: ModelMetadata.id (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY)
        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 com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.saveModel(SQLiteStorageAdapter.java:717)
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$save$3$SQLiteStorageAdapter(SQLiteStorageAdapter.java:315)
        at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$JhGtXoPGeJ7lbNvRHxROfLs-WmE.run(Unknown Source:12) 
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919) 
    Reading subscriptions buffer has failed.
    AmplifyException {message=Error in saving the model: ModelMetadata[id=dbd3acc2-52b7-4006-80aa-fec76ce3c2f2], cause=android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: ModelMetadata.id (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY), recoverySuggestion=See attached exception for details.}
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$save$3$SQLiteStorageAdapter(SQLiteStorageAdapter.java:333)
        at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$JhGtXoPGeJ7lbNvRHxROfLs-WmE.run(Unknown Source:12)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: ModelMetadata.id (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY)
        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 com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.saveModel(SQLiteStorageAdapter.java:717)
        at com.amplifyframework.datastore.storage.sqlite.SQLiteStorageAdapter.lambda$save$3$SQLiteStorageAdapter(SQLiteStorageAdapter.java:315)
        at com.amplifyframework.datastore.storage.sqlite.-$$Lambda$SQLiteStorageAdapter$JhGtXoPGeJ7lbNvRHxROfLs-WmE.run(Unknown Source:12) 
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919) 
I/amplify:aws-datastore: Stopping synchronization with remote API.
    Stopping subscription processor.
I/amplify:aws-datastore: Stopped subscription processor.
godlesscherry commented 4 years ago

+1 for @Switcher05

TLDR: In the interest of following this tutorial, This error can be ignored, I have continued with the next steps and was able to get the appropriate logs. We can just monitor logcat with the search filter as com.example.todo I/Tutorial:

2020-10-17 19:55:40.183 11939-11981/com.example.todo I/Tutorial: Saved item: Build Android application 2020-10-17 19:56:35.742 11939-11981/com.example.todo I/Tutorial: Saved item: Finish quarterly taxes

This happens when the Datastore is trying to authenticate according to : https://github.com/aws-amplify/amplify-android/issues/802

As we are using a local datastore we can conveniently continue with the next steps :)

IMHO there should be a warning or caveat in the guide as I wasted close to 20min trying to debug this ;)

jamesonwilliams commented 3 years ago

We believe this issue has been fixed in recent versions of Amplify Android. If you see this occurring, please comment and we will reopen.