我正在尝试在Android应用程序中使用AWS CloudWatch Log。 我为aws-client进行了以下配置:
val basicAWSCredentials = BasicAWSCredentials(
“Xxxxxx”,
“Yyyyyy”
)
val awsLogsClientBuilder = AWSLogsClientBuilder.standard()
awsLogsClientBuilder.region = Regions.EU_WEST_2.name
awsLogsClientBuilder.credentials = AWSStaticCredentialsProvider(basicAWSCredentials)
awsClient = awsLogsClientBuilder.build()
在build.gradle中,我拥有
implementation ("com.amazonaws:aws-java-sdk-logs:1.11.367") {
exclude module: 'joda-time'
}
该应用程序在awsLogsClientBuilder.build()
处崩溃,但以下情况除外:
E / Android运行时:致命异常:主要 流程:com.xxxxxx.xxxxx,PID:28703 java.lang.NoSuchFieldError:没有类型为Lorg / apache / http / conn / ssl / AllowAllHostnameVerifier的静态字段INSTANCE;在类Lorg / apache / http / conn / ssl / AllowAllHostnameVerifier中;或其超类(“ org.apache.http.conn.ssl.AllowAllHostnameVerifier的声明”出现在/system/framework/framework.jar!classes2.dex中)...
我也尝试使用android特定库:
androidSdkLogsVersion = "2.6.24"
implementation "com.amazonaws:aws-android-sdk-logs:$androidSdkLogsVersion"
和/或
implementation "com.amazonaws:aws-android-sdk-mobile-client:$androidSdkLogsVersion"
但是如果我将其与java sdk一起使用,则会在编译时出现错误:
程序类型已经存在:com.amazonaws.ResponseMetadata
如果不导入java-sdk,则会在编译时出现错误,因为不再找到类AWSLogsClientBuilder
。
我应该如何在Android上创建记录器?
答案 0 :(得分:0)
这就是我所做的:
在build.gradle
androidSdkLogsVersion = "2.6.24"
implementation "com.amazonaws:aws-android-sdk-logs:$androidSdkLogsVersion"
并配置记录器:
val basicAWSCredentials = BasicAWSCredentials("xxxxx","yyyy")
val awsClient = AmazonCloudWatchLogsClient(basicAWSCredentials)
val regions: Regions = Regions.EU_WEST_1
awsClient.setRegion(Region.getRegion(regions.getName()))
答案 1 :(得分:0)
我建议使用AWS Java SDK V2 。在Android上工作时,它将允许您使用备用HTTP运行时,并避免与Apache客户端发生混乱。
AWS Java SDK V2存储库中的GitHub Issue #1180解决了该主题。
在模块级build.gradle
中,添加依赖项:
dependencies {
implementation 'software.amazon.awssdk:cloudwatch:2.13.49'
implementation 'software.amazon.awssdk:url-connection-client:2.13.49'
}
现在,初始化CloudWatch客户端:
val cloudwatch = CloudWatchClient.builder()
.httpClient(UrlConnectionHttpClient.create())
.region(Region.US_EAST_1)
.credentialsProvider(yourCredentialsHere())
.build()