Closed kopevgale closed 6 years ago
Sorry for the inconvenience caused.
This issue happens because you have added CognitoUserPool
in the awsconfiguration.json
file but not added the dependencies for userpools in the build.gralde
AWSMobileClient errored out because it was not able to find CognitoUserPoolsSignInProvider
class which comes from aws-android-sdk-auth-userpools
package.
Can you check if the awsconfiguration.json
file has CognitoUserPool
in it? Have you created a UserPool (Amazon Cognito UserPools
) in the backend console?
If you add the dependencies as follows, the AWSMobileClient will be able to proceed in initializing.
dependencies {
// Mobile Client for initializing the SDK
compile ('com.amazonaws:aws-android-sdk-mobile-client:2.6.+@aar') { transitive = true; }
// Cognito UserPools for SignIn
compile 'com.android.support:support-v4:24.+'
compile ('com.amazonaws:aws-android-sdk-auth-userpools:2.6.+@aar') { transitive = true; }
// Sign in UI Library
compile 'com.android.support:appcompat-v7:24.+'
compile ('com.amazonaws:aws-android-sdk-auth-ui:2.6.+@aar') { transitive = true; }
}
this is my awsconfiguration.json
{
"UserAgent": "MobileHub/1.0",
"Version": "1.0",
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "*******",
"Region": "us-east-2"
}
}
},
"IdentityManager": {
"Default": {}
},
"PinpointAnalytics": {
"Default": {
"AppId": "**********",
"Region": "us-east-1"
}
},
"PinpointTargeting": {
"Default": {
"Region": "us-east-1"
}
}
}
For security reasons, I modified your awsconfiguration.json to not expose the pool id and app id. Do you mean to say that your app crashes even if CognitoUserPool
is not present in the awsconfiguration.json? Do you see a crash with the above contents?
pool name must match the name of the application?
Case-1: If you want to add User SignIn feature to your app with Amazon Cognito UserPools, follow the steps here: Setup Backend for UserPools and then Add UserPools dependencies to your app. If you follow all the steps laid out in the above two sections, you will be able to add user sign in feature to your app.
Case-2: If you do not intend to add User SignIn feature in your app, you can skip adding CognitoUserPool information in awsconfiguration.json.
Case-3: You have added CognitoUserPool in awsconfiguration.json but not imported the appropriate dependencies in gradle, which tells AWSMobileClient that you are planning to integrate UserPools in your application.Since the dependencies are not available, the AWSMobileClient throws an exception.
The exception is thrown when you are in case-3.
word " activity_authenticator " in line "setContentView(R.layout.activity_authenticator);" is red. i see "cannot resolve symbol activity authentificator" . How i can fix it? this is my AuthenticatorActivity.java:
package com.amazonaws.mobile.samples.mynotes;
import android.app.Activity;
import android.os.Bundle;
import com.amazonaws.mobile.auth.ui.SignInUI;
import com.amazonaws.mobile.client.AWSMobileClient;
import com.amazonaws.mobile.client.AWSStartupHandler;
import com.amazonaws.mobile.client.AWSStartupResult;
import android.app.Activity;
/**
* Created by Genius on 10.02.2018.
*/
public class AuthenticatorActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_authenticator);
AWSMobileClient.getInstance().initialize(this, new AWSStartupHandler() {
@Override
public void onComplete(AWSStartupResult awsStartupResult) {
SignInUI signin = (SignInUI) AWSMobileClient.getInstance().getClient(AuthenticatorActivity.this, SignInUI.class);
signin.login(AuthenticatorActivity.this, NoteListActivity.class).execute();
}
}).execute();
}
}
}
When you created an activity in Android Studio with the name "AuthenticatorActivity", it would create the respective layout/xml file in your resources folder with the name activity_authenticator. Can you check if you have this file? Otherwise, you should create a new activity with this name and copy the code in your onCreate and ensure you have the corresponding layout/xml file associated with your activity.
@kopevgale Just checking if you are unblocked from this issue or are there any other issues pending here? Please let us know. Thank you!
@kvasukib, sanx you very mutch, this work. I also configure sdk in build.gradle (module app):
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.amazonaws.mobile.samples.notes"
minSdkVersion 23
targetSdkVersion 26```
Re-open or create another issue if further discussion is required.
@kopevgale hi, I am getting this issue in my Andriod app, I do have the awsconfiguration.Json file in a raw folder, and I do have all the dependencies in my build.gradle that you mentioned above.
W/AWSMobileClient: getCredentials: Failed to getCredentials from Cognito Identity com.amazonaws.services.cognitoidentity.model.NotAuthorizedException: Unauthenticated access is not supported for this identity pool. (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: NotAuthorizedException; Request ID: 5dd821b5-1826-11e9-96c7-ddcc1850988a)
I couldn't can you let me know when do i have these type of exceptions?
@aswinkumarpopuri Have you enabled "Access to Unauthenticated Identities" in your Cognito Identity Pool?
In the Aws console or thorugh the app?, how can I provide access for unauthenticated users through the code ?
Thanks in advance
In the AWS console. This is an option that can be found in the Cognito Identity pool settings.
@kopevgale We have added new features to AWSMobileClient
which will solve your use-case.
AWSMobileClient
provides client APIs and building blocks for developers who want to create user authentication experiences. It supports the following new features:AWSMobileClient
offers on-demand querying for the “login state” of a user in the application.Cognito User Pools
JWT Token
and AWS Credentials
from Cognito Identity
.AWSMobileClient
is optimized to account for applications transitioning from offline to online connectivity, and refreshing credentials at the appropriate time so that errors do not occur when actions are taken and connectivity is not available.AWSMobileClient
client supports easy “drop-in” UI for your application.signUp
, signIn
, confirmSignIn
, etc.Note: The existing methods of
AWSMobileClient
are deprecated and will be removed in a future minor version.AWSMobileClient
now takes a dependency onAWSCognitoIdentityProvider
(Cognito User Pools SDK) package to offer integration withCognitoUserPools
. When using the new drop-in UI,AWSAuthUI
andSocial sign-in
features continue to be pluggable dependencies forAWSMobileClient
.
All documentation is now centralized at https://aws-amplify.github.io/
Please upgrade to the latest version (2.10.1
) to get the latest updates.
I follow the manual Connecting to Mobile Backend I start him in real phone, non virtual android 6 version my AndroidManifest.xml must contain:
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
I Add dependencies to your app/build.gradle. These libraries enable basic AWS functions, like credentials, and analytics.
dependencies { compile ('com.amazonaws:aws-android-sdk-mobile-client:2.6.7@aar') { transitive = true; } }
I Add the following code to the onCreate method of your main or startup activity. This will establish a connection with AWS Mobile. AWSMobileClient is a singleton that will be an interface for your AWS services.
I get the following error:
`$ adb shell am start -n "com.amazonaws.mobile.samples.mynotes/com.amazonaws.mobile.samples.mynotes.NoteListActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Error while executing: am start -n "com.amazonaws.mobile.samples.mynotes/com.amazonaws.mobile.samples.mynotes.NoteListActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.amazonaws.mobile.samples.mynotes/.NoteListActivity } Error type 3 Error: Activity class {com.amazonaws.mobile.samples.mynotes/com.amazonaws.mobile.samples.mynotes.NoteListActivity} does not exist.
Errors while Launching activity:
this is my NoteListActivity.java :