Android Studio Gradle: Cannot resolve symbol 'amazonaws'

Viewed 1414

I'm having an issue with importing amazonaws in my gradle and would greatly appreciate any help. Thanks!

Problem:

I'm attempting to import 'com.amazonaws.auth.*' into my build.gradle, however a red line appears under the statement stating "Cannot resolve symbol 'amazonaws'".

What I've attempted:

  • Sync Gradle and rebuild
  • Invalidate cache and restart
  • Attempted to follow the answer here to no avail

build.gradle code:

buildscript {
    ...

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.amazonaws:aws-java-sdk-core:1.11.5'
    }
}

import com.amazonaws.auth.*

def getAwsReadOnlyCredentials = {
    ...
    return new DefaultAWSCredentialsProviderChain().getCredentials()
}

AWSCredentials libraryCredentials = getAwsReadOnlyCredentials()

allprojects {
    repositories {
        google()
        jcenter()

        maven {
            ...
        }
    }
}

...
2 Answers

you need to import the artifacts from repository mavenCentral() - and don't add dependencies into the buildscript classpath, but a module's dependencies. it seems to me, as if you were mixing up Java with Gradle syntax, while depending on the wrong one library. this import statement and the AWSCredentials (with a high probability) belong into a .java file and not a .gradle file.

for example: this one looks promising:

dependencies {
    implementation "com.amazonaws:aws-android-sdk-core:2.6.31"
}

In my case, just Invalidating the caches and restarting the android studio solved the problem. In order to do that you need to go to the Files -> Invalidate Caches/ Restart.

We do not need the mavenCentral() repository to be exact to download the aws dependencies. Only jcenter() should suffice.

And also consider adding apply plugin 'java' in your build.gradle.

Related