AWS在Android应用程序中放大Cognito认证错误

AWS在Android应用程序中放大Cognito认证错误,android,authentication,amazon-cognito,aws-amplify,Android,Authentication,Amazon Cognito,Aws Amplify,我正在遵循Amplify文档为我的Android应用程序添加身份验证。我在这一行得到一个AuthException: Amplify.addPlugin(AWSCognitoAuthPlugin()) 我确实创建了一个用户池。我是否需要以某种方式连接它?我想,AWSMobileClient有一些问题 这是我的应用程序课程: 类AppUtils:Application(){ 重写fun onCreate(){ super.onCreate() 试一试{ Amplify.addPlugin(AWS

我正在遵循Amplify文档为我的Android应用程序添加身份验证。我在这一行得到一个
AuthException

Amplify.addPlugin(AWSCognitoAuthPlugin())
我确实创建了一个用户池。我是否需要以某种方式连接它?我想,
AWSMobileClient
有一些问题

这是我的
应用程序
课程:

类AppUtils:Application(){
重写fun onCreate(){
super.onCreate()
试一试{
Amplify.addPlugin(AWSCognitoAuthPlugin())
放大.配置(applicationContext)
Log.d(标签“初始化放大”)
}捕获(错误:异常){
Log.e(标记“无法初始化放大”,错误)
}
}
}
以下是logcat中显示的错误:

AuthException{message=未能实例化AWSMobileClient,原因=java.lang.RuntimeException:未使用Cognito标识或Cognito用户池。必须至少存在一个才能使用AWSMobileClient.,recoverySuggestion=有关详细信息,请参阅附加的异常}


该错误表示在配置文件中找不到标识或用户池

首先确保已完成以下步骤:

  • 放大初始化
  • 放大添加验证
  • 放大推力
完成后,您的
app/src/main/res/raw
目录中应该有一个
configuration.json
和一个
awsconfiguration.json

您的
configuration.json
应该如下所示:

{
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                            "Region": "us-east-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "us-east-1_xxxxxxxxx",
                        "AppClientId": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
                        "AppClientSecret":
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                        "Region": "us-east-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH"
                    }
                }
            }
        }
    }
}
{
    "UserAgent": "aws-amplify-cli/0.1.0",
    "Version": "0.1.0",
    "IdentityManager": {
        "Default": {}
    },
    "CredentialsProvider": {
        "CognitoIdentity": {
            "Default": {
                "PoolId": "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                "Region": "us-east-1"
            }
        }
    },
    "CognitoUserPool": {
        "Default": {
            "PoolId": "us-east-1_xxxxxxxxx",
            "AppClientId": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
            "AppClientSecret":
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "Region": "us-east-1"
        }
    },
    "Auth": {
        "Default": {
            "authenticationFlowType": "USER_SRP_AUTH"
        }
    }
}
您的
awsconfiguration.json
应该如下所示:

{
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                            "Region": "us-east-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "us-east-1_xxxxxxxxx",
                        "AppClientId": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
                        "AppClientSecret":
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                        "Region": "us-east-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH"
                    }
                }
            }
        }
    }
}
{
    "UserAgent": "aws-amplify-cli/0.1.0",
    "Version": "0.1.0",
    "IdentityManager": {
        "Default": {}
    },
    "CredentialsProvider": {
        "CognitoIdentity": {
            "Default": {
                "PoolId": "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                "Region": "us-east-1"
            }
        }
    },
    "CognitoUserPool": {
        "Default": {
            "PoolId": "us-east-1_xxxxxxxxx",
            "AppClientId": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
            "AppClientSecret":
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "Region": "us-east-1"
        }
    },
    "Auth": {
        "Default": {
            "authenticationFlowType": "USER_SRP_AUTH"
        }
    }
}

如果您刚刚添加了Cognito,请运行

amplify update api
使用Cognito作为身份验证模式

然后跑

amplify push