Question

I am trying to follow a tutorial for DynamoDB on AWS website : http://aws.amazon.com/articles/7439603059327617 I downloaded the file, imported it to Eclipse, imported all the necessary libraries (or literally, all the libraries that came with the github file), but DynamoDBManager.java would keep giving me the dreaded "The import com.amazon... cannot be resolved" error for the following lines:

import com.amazonaws.services.dynamodbv2.model.DynamoDBAttribute;
import com.amazonaws.services.dynamodbv2.model.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.model.DynamoDBMapper;
import com.amazonaws.services.dynamodbv2.model.DynamoDBScanExpression;
import com.amazonaws.services.dynamodbv2.model.DynamoDBTable;
import com.amazonaws.services.dynamodbv2.model.PaginatedScanList;

But library is imported for all other classes such as

import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import com.amazonaws.services.dynamodbv2.model.DeleteTableRequest;
import com.amazonaws.services.dynamodbv2.model.DescribeTableRequest;
import com.amazonaws.services.dynamodbv2.model.DescribeTableResult;
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
import com.amazonaws.services.dynamodbv2.model.KeyType;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException;
import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType;

Did anyone else run into a similar problem? Could you please direct me in a right direction?!

Thank you in advance & for reading!

Was it helpful?

Solution

I came across a similar issue while following a related tutorial http://mobile.awsblog.com/post/Tx1U4RV2QI1MVWS/Amazon-DynamoDB-on-Mobile-Part-1-Loading-Data https://github.com/awslabs/aws-sdk-android-samples/tree/master/DynamoDBMapper_UserPreference

I'm using the latest version of Android Studio (0.8.1) and AWS SDK for Android (1.7.1.1). It looks like you're using the wrong package path.

For

import com.amazonaws.services.dynamodbv2.model.DynamoDBAttribute;
import com.amazonaws.services.dynamodbv2.model.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.model.DynamoDBMapper;
import com.amazonaws.services.dynamodbv2.model.DynamoDBScanExpression;
import com.amazonaws.services.dynamodbv2.model.DynamoDBTable;
import com.amazonaws.services.dynamodbv2.model.PaginatedScanList;

you're using com.amazonaws.services.dynamodbv.model when it should be com.amazonaws.services.dynamodbv2.datamodeling. For more proof/documentation about the packages you can look at dynmodbv2 here to see that they are not deprecated. Change your package path to reflect this:

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedScanList;

and you should hopefully only need to use one of the following:

  • aws-android-sdk-VERSION.jar. Contains all necessary files (including third-party dependencies) for all supported AWS services. All class files were compiled without the debug option.
  • aws-android-sdk-VERSION-debug.jar. Contains all files (including third-party dependencies) necessary for debugging. The code was compiled with the debug option on with all symbols retained.

For more on the jars in the AWS SDK for Android see the official documentation here

Other Potential Issues

(Should only be relevant for AWS SDK for 1.7.1.1 and below if the bug doesn't get fixed in the next rev)

My issue was different in that even though I had the correct package path as per documentation, Android Studio's Intellij couldn't find dynamodbv2.datamodeling that is, when typing import com.amazonaws.services.dynamodbv2. it didn't suggest datamodeling, only utility and model. Trying import com.amazonaws.services.dynamodbv2.* didn't fix the issue either. Because of this it seems that the datamodeling package isn't wrapped into the two above mentioned packages which in theory are supposed to be all encompassing. To get datamodeling and fix the issue I had in regards to the same objects not being found (DynamoDBAttribute, DynamoDBHashKey, etc.) I had to add as library/file dependencies aws-android-sdk-1.7.1.1-ddb-mapper.jar and aws-android-sdk-1.7.1.1-ddb.jar and cleaned my project at which point Intellij could see datamodeling when typing import and the sample project could compile.

I imagine you know how to import libraries in your platform as you mentioned importing, but make sure it's only the individual files you need and you don't include aws-android-sdk-1.7.1.1-debug.jar or aws-android-sdk-1.7.1.1.jar with them. So for example, my Android Studio module gradle build file dependencies looks like:

dependencies {
    compile files('libs/aws-android-sdk-1.7.1.1-ddb-mapper.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-ddb.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-autoscaling.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-cloudwatch.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-core.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-ec2.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-elb.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-s3.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-sdb.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-ses.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-sns.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-sqs.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-sts.jar')
}

The issue I had seems to be a bug where ddb and ddb-mapper weren't included in what should be the all encompassing aws-android-sdk-1.7.1.1-debug.jar and aws-android-sdk-1.7.1.1.jar. As such, I have reported on GitHub (https://github.com/aws/aws-sdk-android/issues/18) and hopefully the next rev will fix this issue and it will no longer be relevant and you should only need aws-android-sdk-1.7.1.1-debug.jar or aws-android-sdk-1.7.1.1.jar

OTHER TIPS

I am not 100% sure, but after digging the documentation, it seems like the classes that cannot be resolved are deprecated and are no longer included in the jar files... They do still exist in the source code folder, but seeing that since they are deprecared, I guess there is no use trying to follow the tutorial...

Dynamo DB made many breaking changes (requires code change) when they moved to DynamoDB V2.

You need to ensure that the latest SDK is installed and you re using it - In eclipse, you need to also mention which AWS SDK to use (point it to the latest). Though eclipse AWS plugin downloads the latest SDK automatically, it doesnt update the version number to us the latest. You need to update this yourself.

It is written in AWS Documentation what to do:

Existing Application The samples included with the AWS SDK for Android are provided as standalone projects set up for you to try out. To use AWS with an existing application, follow these steps:

  1. Create a libs directory within your Android project directory if one does not already exist.
  2. Copy either a bundled JAR for all services or the specific JARs for the services you wish to use.You have 3 options: Add aws-android-sdk-VERSION-debug.jar. This JAR creates the largest APK, but allows for full stack traces during development. Add aws-android-sdk-VERSION.jar. This JAR creates a smaller APK and a simple bundle when releasing your application. Add the aws-android-sdk-VERSION-core.jar plus the JARs for the individual services your project will use. This method creates the smallest APK, but requires a more complicated setup. Note, copying both bundled JARs and service JARs will cause errors.
  3. In Eclipse, go to your project, select Properties -> Java Build Path -> Libraries and click Add JARs. Then select the JARs you added to your libs directory.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top