gpt4 book ai didi

amazon-web-services - AwsS3 客户端在初始化时抛出错误

转载 作者:行者123 更新时间:2023-12-05 05:08:40 24 4
gpt4 key购买 nike

每当我尝试初始化 aws s3 客户端时,我都会看到此崩溃。我尝试寻找解决方案,但没有找到任何解决方案。

BasicAWSCredentials awsCreds = new BasicAWSCredentials(amazonAccessId, amazonSecretKey);
Amazon S3 s3Client = AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.withRegion(Regions.AP_SOUTH_1)
.build();

Gradle 文件

dependencies {
implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.641')
implementation 'com.amazonaws:aws-java-sdk-s3:1.11.641'
}

这会在 .build() 行上引发一个错误,提示 Failed resolution of: Ljavax/management/MBeanServerFactory;

--------- beginning of crash
2019-09-30 17:48:02.148 20191-20191/com.tactopus.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tactopus.app, PID: 20191
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/management/MBeanServerFactory;
at com.amazonaws.jmx.MBeans.getMBeanServer(MBeans.java:111)
at com.amazonaws.jmx.MBeans.registerMBean(MBeans.java:50)
at com.amazonaws.jmx.SdkMBeanRegistrySupport.registerMetricAdminMBean(SdkMBeanRegistrySupport.java:27)
at com.amazonaws.metrics.AwsSdkMetrics.registerMetricAdminMBean(AwsSdkMetrics.java:398)
at com.amazonaws.metrics.AwsSdkMetrics.<clinit>(AwsSdkMetrics.java:359)
at com.amazonaws.metrics.AwsSdkMetrics.addAll(AwsSdkMetrics.java:662)
at com.amazonaws.services.s3.AmazonS3Client.<clinit>(AmazonS3Client.java:406)
at com.amazonaws.services.s3.AmazonS3Builder$1.apply(AmazonS3Builder.java:35)
at com.amazonaws.services.s3.AmazonS3Builder$1.apply(AmazonS3Builder.java:32)
at com.amazonaws.services.s3.AmazonS3ClientBuilder.build(AmazonS3ClientBuilder.java:64)
at com.amazonaws.services.s3.AmazonS3ClientBuilder.build(AmazonS3ClientBuilder.java:28)
at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
at com.tactopus.app.AWS.S3DownloadAndUpdate.init(S3DownloadAndUpdate.java:98)
at com.tactopus.app.AWS.S3DownloadAndUpdate.<init>(S3DownloadAndUpdate.java:64)
at com.tactopus.app.presenter.BookDescriptionActivityPresenter.onClick(BookDescriptionActivityPresenter.java:46)
at com.tactopus.app.view.BookDescriptionActivity$3.onClick(BookDescriptionActivity.java:166)
at android.view.View.performClick(View.java:7352)
at android.widget.TextView.performClick(TextView.java:14177)
at android.view.View.performClickInternal(View.java:7318)
at android.view.View.access$3200(View.java:846)
at android.view.View$PerformClick.run(View.java:27800)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7050)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.management.MBeanServerFactory" on path: DexPathList[[zip file "/data/app/com.tactopus.app-IcaP3SsuBAnlY85tNBJ8fw==/base.apk"],nativeLibraryDirectories=[/data/app/com.tactopus.app-IcaP3SsuBAnlY85tNBJ8fw==/lib/arm64, /system/lib64, /system/vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)

最佳答案

我今天遇到了这个问题,看起来 MBeanServerFactory 不是 AWS 的 Java SDK 的一部分。

改用下面的依赖

implementation 'com.amazonaws:aws-android-sdk-core:2.6.0'
implementation 'com.amazonaws:aws-android-sdk-cognito:2.2.0'
implementation 'com.amazonaws:aws-android-sdk-s3:2.6.0'

您可以使用 CognitoCachingCredentialsProvider 来初始化您的 AmazonS3 客户端。转到您的 Amazon Cognito Console ,然后创建一个身份池。确保您已授予正确的权限(您可以通过转到 IAM 控制面板进行检查,然后在“角色”选项卡下检查您刚刚创建的身份池并添加 AmazonS3FullAccess 策略)。

创建身份池后,您将获得如下所示的示例代码

CognitoCachingCredentialsProvider credentialsProvider;
credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(),
"ap-southeast-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Identity Pool ID
Regions.AP_SOUTHEAST_1 // Region
);

使用此 credentialsProvider 对象来初始化您的 AmazonS3 客户端

AmazonS3 s3Client = new AmazonS3Client(credentialsProvider);

关于amazon-web-services - AwsS3 客户端在初始化时抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58167829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com