4

I`ve followed this steps to add the AWS Mobile SDK to my app. When I reach step 4 of the "Connect your backend" section and try to compile my app I get the following error:

Error:(20, 9) error: cannot find symbol variable AWSMobileClient

I've looked up the documentation here and found that the AWSMobileClient class should be inside the com.amazonaws.mobile.client.AWSMobileClient package, but when I try to manually import the mentioned package, I get the following error:

Error:(9, 28) error: package com.amazonaws.mobile does not exist

My current project files look like these:

MainActivity.java

package point.cursoandroid.com.medpoint;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

    private Button botaoLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AWSMobileClient.getInstance().initialize(this).execute();
        botaoLogin = (Button) findViewById(R.id.botaoLoginId);

        botaoLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, LoginActivity.class));
            }
        });
    }
}

app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"

    defaultConfig {
        applicationId "point.cursoandroid.com.medpoint"
        minSdkVersion 25
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:27.+'
    compile 'com.android.support:support-v4:27.+'
    compile 'com.android.support:design:27.+'
    compile 'com.amazonaws:aws-android-sdk-core:2.6.+'
    compile 'com.amazonaws:aws-android-sdk-s3:2.6.+'
    compile 'com.amazonaws:aws-android-sdk-ddb:2.6.+'
}

Using AndroidStudio 3.0.1 So, any ideas?

Pedro
  • 333
  • 1
  • 5
  • 24

1 Answers1

12

You need to import the appropriate dependencies in build.gradle

dependencies {
    implementation ('com.amazonaws:aws-android-sdk-mobile-client:2.16.+@aar') { transitive = true; }
}

Perform a gradle sync and you should be able to import the class and package.

EDIT: Replace 2.16.+ with the latest version of the AWS SDK for Android. The latest version can be found either in GitHub or Maven Repository.

More information about AWSMobileClient can be found in the Documentation and APIReference.

Karthikeyan
  • 1,411
  • 1
  • 13
  • 13
  • Thank you. Where were you able to find this info? – Pedro Feb 11 '18 at 13:55
  • It's in step (3) of the docs: https://docs.aws.amazon.com/aws-mobile/latest/developerguide/getting-started.html#connect-to-your-backend. – Karthikeyan Feb 12 '18 at 03:39
  • The initialize method when called with the context (this), initializes the SDK , fetches the cognito identity. This will give you access to the AWSConfiguration object and the AWSCredentialsProvider object that you can use to instantiate other clients offered by the SDK. When the execute() succeeds, you will be able to access the credentials provider object through AWSMobileClient.getInstance().getCredentialsProvider(). – Karthikeyan Feb 12 '18 at 03:42
  • Its in Get Started guide -> https://docs.aws.amazon.com/aws-mobile/latest/developerguide/getting-started.html – Jay May 28 '18 at 20:56
  • @ShubhamGoel Are you still getting "cannot find symbol variable AWSMobileClient" even after importing the dependency? – Karthikeyan Jul 18 '18 at 16:35
  • Can you try `implementation ('com.amazonaws:aws-android-sdk-mobile-client:2.9.+@aar') { transitive = true; }` – Karthikeyan Dec 28 '18 at 23:42
  • compile is depreciated in the latest versions. – fireball.1 Dec 24 '19 at 08:17