这个错误是由于Amazon SDK的版本不兼容导致的。可以尝试更新SDK版本,或者手动指定适用的Amazon SDK版本。
以下是一个示例代码,可以通过手动指定适用的Amazon SDK版本来解决这个问题:
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
public class MyS3Client {
public AmazonS3 createS3Client() {
AwsClientBuilder.EndpointConfiguration endpointConfig =
new AwsClientBuilder.EndpointConfiguration("https://s3.us-west-2.amazonaws.com", "us-west-2");
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(endpointConfig)
.withCredentials(new DefaultAWSCredentialsProviderChain())
.build();
return s3Client;
}
}
在这里,我们手动指定SDK版本为1.11.375,以解决出现java.lang.NoSuchFieldError: CLIENT_ENDPOINT错误:
dependencies {
// ...
implementation 'com.amazonaws:aws-java-sdk-s3:1.11.375'
// ...
}