我想在我的Amazon AWS服务器中创建一个对象,并添加此类用于AWS上传对象:
package com.appsexpress;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import java.io.File;
import java.io.IOException;
public class UploadObject {
public static void main(String[] args) throws IOException {
String clientRegion = "*** Client region ***";
String bucketName = "*** Bucket name ***";
String stringObjKeyName = "*** String object key name ***";
String fileObjKeyName = "*** File object key name ***";
String fileName = "*** Path to file to upload ***";
try {
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withRegion(clientRegion)
.withCredentials(new ProfileCredentialsProvider())
.build();
// Upload a text string as a new object.
s3Client.putObject(bucketName, stringObjKeyName, "Uploaded
String Object");
// Upload a file as a new object with ContentType and title
specified.
PutObjectRequest request = new PutObjectRequest(bucketName,
fileObjKeyName, new File(fileName));
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("plain/text");
metadata.addUserMetadata("x-amz-meta-title", "someTitle");
request.setMetadata(metadata);
s3Client.putObject(request);
}
catch(AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3
couldn't process
// it, so it returned an error response.
e.printStackTrace();
}
catch(SdkClientException e) {
// Amazon S3 couldn't be contacted for a response, or the
client
// couldn't parse the response from Amazon S3.
e.printStackTrace();
}
}
}
我还按照我必须按照Amazon AWS指令在build.gradle(app)中添加下一行:
dependencies {
implementation 'com.android.support.constraint:constraint-
layout:2.0.0-beta1'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.github.parse-community.Parse-SDK-
Android:parse:1.18.5"
implementation group: 'cz.msebera.android', name: 'httpclient',
version: '4.5.8'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.1.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-vector-drawable:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.amazonaws:aws-java-sdk:1.11.404'
//Base SDK
implementation 'com.amazonaws:aws-android-sdk-core:2.13.5'
//AppSync SDK
implementation 'com.amazonaws:aws-android-sdk-appsync:2.9.0'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.1'
implementation
'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
implementation 'com.amazonaws:aws-android-sdk-s3:2.13.5'
implementation ('com.amazonaws:aws-android-sdk-mobile-
client:2.13.5@aar') { transitive = true }
implementation ('com.amazonaws:aws-android-sdk-auth-
userpools:2.13.5@aar') { transitive = true }
}
,当我运行应用程序时,它给我有关重复类的错误,但我需要同时保留它们 我希望有解决方案。
Duplicate class com.amazonaws.util.AWSRequestMetrics$Field found in modules
aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5)
and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.AWSRequestMetricsFullSupport found in
modules aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-
core:2.13.5) and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.AWSServiceMetrics found in modules aws-
android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and
aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.AbstractBase32Codec found in modules aws-
android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and
aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.AwsHostNameUtils found in modules aws-
android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and
aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.Base16 found in modules aws-android-sdk-
core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-java-
sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.Base16Codec found in modules aws-android-
sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-
java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.Base16Codec$LazyHolder found in modules
aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5)
and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.Base32 found in modules aws-android-sdk-
core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-java-
sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.Base32Codec found in modules aws-android-
sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-
java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.Base32Codec$LazyHolder found in modules
aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5)
and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.Base64 found in modules aws-android-sdk-
core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-java-
sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.Base64Codec found in modules aws-android-
sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-
java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.Base64Codec$LazyHolder found in modules
aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5)
and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.BinaryUtils found in modules aws-android-
sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-
java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.CRC32ChecksumCalculatingInputStream found
in modules aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-
core:2.13.5) and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.ClassLoaderHelper found in modules aws-
android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and
aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.Classes found in modules aws-android-sdk-
core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-java-
sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.Codec found in modules aws-android-sdk-
core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-java-
sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.CodecUtils found in modules aws-android-
sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-
java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.CountingInputStream found in modules aws-
android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and
aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.DateUtils found in modules aws-android-
sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-
java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.EncodingScheme found in modules aws-
android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and
aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.EncodingSchemeEnum found in modules aws-
android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and
aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.EncodingSchemeEnum$1 found in modules
aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5)
and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.EncodingSchemeEnum$2 found in modules
aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5)
and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.EncodingSchemeEnum$3 found in modules
aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5)
and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.HttpClientWrappingInputStream found in
modules aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-
core:2.13.5) and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.IOUtils found in modules aws-android-sdk-
core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-java-
sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.ImmutableMapParameter found in modules
aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5)
and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.ImmutableMapParameter$1 found in modules
aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5)
and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.ImmutableMapParameter$Builder found in
modules aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-
core:2.13.5) and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.LengthCheckInputStream found in modules
aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5)
and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.Md5Utils found in modules aws-android-
sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-
java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.NamespaceRemovingInputStream found in
modules aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-
core:2.13.5) and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class
com.amazonaws.util.NamespaceRemovingInputStream$StringPrefixSlicer found in
modules aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-
core:2.13.5) and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.ResponseMetadataCache found in modules
aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5)
and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.ResponseMetadataCache$InternalCache
found in modules aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-
sdk-core:2.13.5) and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-
sdk-core:1.11.404)
Duplicate class com.amazonaws.util.RuntimeHttpUtils found in modules aws-
android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and
aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.ServiceClientHolderInputStream found in
modules aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-
core:2.13.5) and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.StringInputStream found in modules aws-
android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and
aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.StringUtils found in modules aws-android-
sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-
java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.Throwables found in modules aws-android-
sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-
java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.TimingInfo found in modules aws-android-
sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-
java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.TimingInfoFullSupport found in modules
aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5)
and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.TimingInfoUnmodifiable found in modules
aws-android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5)
and aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-
core:1.11.404)
Duplicate class com.amazonaws.util.ValidationUtils found in modules aws-
android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and
aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.VersionInfoUtils found in modules aws-
android-sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and
aws-java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.XMLWriter found in modules aws-android-
sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-
java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.XmlUtils found in modules aws-android-
sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-
java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Duplicate class com.amazonaws.util.XpathUtils found in modules aws-android-
sdk-core-2.13.5.jar (com.amazonaws:aws-android-sdk-core:2.13.5) and aws-
java-sdk-core-1.11.404.jar (com.amazonaws:aws-java-sdk-core:1.11.404)
Go to the documentation to learn how to <a
href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution
errors</a>.